Documents and examples of PythonMagick Documents and examples of PythonMagick python python

Documents and examples of PythonMagick


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

Example

import PythonMagickimage = 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.jpgJPEG345229

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)


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")


To find out the methods type in Python:

import PythonMagickdir(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']