Documents and examples of PythonMagick

jack picture jack · Nov 16, 2009 · Viewed 48.4k times · Source

Where can I find the document and examples of PythonMagick?

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

Answer

David Kierans picture David Kierans · Mar 4, 2011

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)