Documents and examples of PythonMagick

Question:

Where can I find the document and examples of PythonMagick?

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

Asked By: jack

||

Answers:

EDIT: Nothing to see here. Refer to better answer below.


It is a bindings to the MagickWand API : http://www.assembla.com/wiki/show/pythonmagickwand

So you can use all of the MagickWand API functions.

 #!/usr/bin/python
 import Magick

 # Use the Python Imaging Library to create a Tk display
 dpy = Magick.TkDisplay(startmain=0)

 # Read the image
 img = Magick.read('test.gif')

 # Display the image
 dpy(img)
 dpy(img.Swirl(90))

 dpy.startmain=1
 dpy.show()
Answered By: Natim

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)
Answered By: David Kierans

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']

Answered By: klaus

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")
Answered By: FizxMike

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)

Answered By: 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.

Answered By: zizzler
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.