Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Documents and examples of PythonMagick

Where can I find the document and examples of PythonMagick?

I did a search on Google but no much information was found.

like image 870
jack Avatar asked Nov 16 '09 05:11

jack


5 Answers

I could not find them anywhere either but this is how I went about using it anyway.

Example

import PythonMagick
image = PythonMagick.Image("sample_image.jpg")
print image.fileName()
print image.magick()
print image.size().width()
print image.size().height()

With output like this

sample_image.jpg
JPEG
345
229

To find out what image methods are available for example I looked in the cpp source. Taking the Image object binding: Image implemented in _Image.cpp Or better still look at the suggestion for getting the methods contained in another answer by Klaus on this page.

In this file you'll see lines like this

    .def("contrast", &Magick::Image::contrast)
    .def("convolve", &Magick::Image::convolve)
    .def("crop", &Magick::Image::crop)
    .def("cycleColormap", &Magick::Image::cycleColormap)
    .def("despeckle", &Magick::Image::despeckle)

The bit in quotes maps to the function name of the Image object. Following this approach you can figure out enough to be useful. For example Geometry specific methods are in _Geometry.cpp and the include the usual suspects like

     .def("width", (size_t (Magick::Geometry::*)() const)&Magick::Geometry::width)
    .def("height", (void (Magick::Geometry::*)(size_t) )&Magick::Geometry::height)
    .def("height", (size_t (Magick::Geometry::*)() const)&Magick::Geometry::height)
    .def("xOff", (void (Magick::Geometry::*)(ssize_t) )&Magick::Geometry::xOff)
    .def("xOff", (ssize_t (Magick::Geometry::*)() const)&Magick::Geometry::xOff)
like image 70
David Kierans Avatar answered Nov 07 '22 22:11

David Kierans


From what I can tell, PythonMagick wrapps the Magick++ library. I have been able to copy and paste C++ code using this library into python and it works as expected. Plus the names of the classes and member functions match (where as MagickWand seems to be totally different).

    import PythonMagick as Magick
    img = Magick.Image("testIn.jpg")
    img.quality(100) #full compression
    img.magick('PNG')
    img.write("testOut.png")
like image 19
FizxMike Avatar answered Nov 08 '22 00:11

FizxMike


To find out the methods type in Python:

import PythonMagick
dir(PythonMagick.Image())

Then you get an output like this:

['__class__', '__delattr__', '__dict__', '__doc__', '__eq__', '__format__', '__ge__', '__getattribute__', '__gt__', '__hash__', '__init__', '__instance_size__', '__le__', '__lt__', '__module__', '__ne__', '__new__', '__reduce__', '__reduce_ex__', '__repr__', '__setattr__', '__sizeof__', '__str__', '__subclasshook__', '__weakref__', 'adaptiveThreshold', 'addNoise', 'adjoin', 'affineTransform', 'animationDelay', 'animationIterations', 'annotate', 'antiAlias', 'attribute', 'backgroundColor', 'backgroundTexture', 'baseColumns', 'baseFilename', 'baseRows', 'blur', 'border', 'borderColor', 'boundingBox', 'boxColor', 'cacheThreshold', 'channel', 'channelDepth', 'charcoal', 'chop', 'chromaBluePrimary', 'chromaGreenPrimary', 'chromaRedPrimary', 'chromaWhitePoint', 'classType', 'clipMask', 'colorFuzz', 'colorMap', 'colorMapSize', 'colorSpace', 'colorize', 'columns', 'comment', 'compare', 'compose', 'composite', 'compressType', 'contrast', 'convolve', 'crop', 'cycleColormap', 'debug', 'defineSet', 'defineValue', 'density', 'depth', 'despeckle', 'directory', 'display', 'draw', 'edge', 'emboss', 'endian', 'enhance', 'equalize', 'erase', 'fileName', 'fileSize', 'fillColor', 'fillPattern', 'fillRule', 'filterType', 'flip', 'floodFillColor', 'floodFillOpacity', 'floodFillTexture', 'flop', 'font', 'fontPointsize', 'fontTypeMetrics', 'format', 'frame', 'gamma', 'gaussianBlur', 'geometry', 'gifDisposeMethod', 'iccColorProfile', 'implode', 'interlaceType', 'iptcProfile', 'isValid', 'label', 'lineWidth', 'magick', 'magnify', 'map', 'matte', 'matteColor', 'matteFloodfill', 'meanErrorPerPixel', 'medianFilter', 'minify', 'modifyImage', 'modulate', 'modulusDepth', 'monochrome', 'montageGeometry', 'negate', 'normalize', 'normalizedMaxError', 'normalizedMeanError', 'oilPaint', 'opacity', 'opaque', 'page', 'penColor', 'penTexture', 'ping', 'pixelColor', 'process', 'profile', 'quality', 'quantize', 'quantizeColorSpace', 'quantizeColors', 'quantizeDither', 'quantizeTreeDepth', 'raise', 'read', 'readPixels', 'reduceNoise', 'registerId', 'renderingIntent', 'resolutionUnits', 'roll', 'rotate', 'rows', 'sample', 'scale', 'scene', 'segment', 'shade', 'sharpen', 'shave', 'shear', 'signature', 'size', 'solarize', 'spread', 'statistics', 'stegano', 'stereo', 'strokeAntiAlias', 'strokeColor', 'strokeDashOffset', 'strokeLineCap', 'strokeLineJoin', 'strokeMiterLimit', 'strokePattern', 'strokeWidth', 'subImage', 'subRange', 'swirl', 'syncPixels', 'textEncoding', 'texture', 'threshold', 'throwImageException', 'tileName', 'totalColors', 'transform', 'transformOrigin', 'transformReset', 'transformRotation', 'transformScale', 'transformSkewX', 'transformSkewY', 'transparent', 'trim', 'type', 'unregisterId', 'unsharpmask', 'verbose', 'view', 'wave', 'write', 'writePixels', 'x11Display', 'xResolution', 'yResolution', 'zoom']

like image 19
klaus Avatar answered Nov 07 '22 22:11

klaus


For anyone who is still trying to find the documentation of PythonMagick, PythonMagick is exactly the same as Magick++ (API for C++). here is the Magick++ documentation. For some specific parameter, you will need to find the type then the enumeration (e.g. gravity->PythonMagick.GravityType.thegravityyouwant)

like image 2
Smelly Potato Avatar answered Nov 07 '22 23:11

Smelly Potato


PythonMagick isn't exactly the same as Magick++, it maps to a subset of Magick++. So if you start trying to use it based on the C++ documentation, you'll eventually run into something that isn't mapped. After wasting a lot of time (in my 30 years as a developer) with inadequately-documented libraries, I've developed a rule: If it isn't properly documented, don't use it.

I eventually did what I needed to do using python3-PIL. It's a pity, because ImageMagick is really nice to use from C++. But I recommend my rule. In the long run, it will save you a lot of time.

like image 2
zizzler Avatar answered Nov 08 '22 00:11

zizzler