Documents and examples of PythonMagick

后端 未结 6 962
长发绾君心
长发绾君心 2020-12-04 18:09

Where can I find the document and examples of PythonMagick?

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

相关标签:
6条回答
  • 2020-12-04 18:43

    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)

    0 讨论(0)
  • 2020-12-04 18:45

    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")
    
    0 讨论(0)
  • 2020-12-04 18:48

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

    0 讨论(0)
  • 2020-12-04 18:50

    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)
    
    0 讨论(0)
  • 2020-12-04 19:00

    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()
    
    0 讨论(0)
  • 2020-12-04 19:01

    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.

    0 讨论(0)
提交回复
热议问题