PythonMagick的文档和示例

jac*_*ack 31 python imagemagick

我在哪里可以找到PythonMagick的文档和示例?

我在Google上搜索过,但没有找到太多信息.

Dav*_*ans 32

我无法在任何地方找到它们,但无论如何这就是我使用它的方式.

import PythonMagick
image = PythonMagick.Image("sample_image.jpg")
print image.fileName()
print image.magick()
print image.size().width()
print image.size().height()
Run Code Online (Sandbox Code Playgroud)

像这样的输出

sample_image.jpg
JPEG
345
229
Run Code Online (Sandbox Code Playgroud)

为了找出可用的图像方法,我查看了cpp源代码.采用Image对象绑定:在_Image.cpp中实现的图像 或者更好地看看Klaus 在此页面上获取另一个答案中包含的方法的建议.

在这个文件中你会看到这样的行

    .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)
Run Code Online (Sandbox Code Playgroud)

引号中的位映射到Image对象的函数名称.按照这种方法,您可以找出足够有用的方法.例如,Geometry特定的方法在_Geometry.cpp中,并且包括通常的嫌疑人

     .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)
Run Code Online (Sandbox Code Playgroud)


小智 18

要找出Python中的方法类型:

import PythonMagick
dir(PythonMagick.Image())
Run Code Online (Sandbox Code Playgroud)

然后你得到这样的输出:

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


Fiz*_*ike 17

据我所知,PythonMagick包含了Magick ++库.我已经能够使用这个库将C++代码复制并粘贴到python中,并且它按预期工作.此外,类和成员函数的名称相匹配(MagickWand似乎完全不同).

    import PythonMagick as Magick
    img = Magick.Image("testIn.jpg")
    img.quality(100) #full compression
    img.magick('PNG')
    img.write("testOut.png")
Run Code Online (Sandbox Code Playgroud)


Nat*_*tim -14

编辑:这里没什么可看的。参考下面更好的答案。


它是MagickWand API的绑定:http ://www.assembla.com/wiki/show/pythonmagickwand

因此您可以使用所有 MagickWand API 函数。

 #!/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()
Run Code Online (Sandbox Code Playgroud)

  • 我不知道为什么这会被接受,这是不正确的。有*两种不同的 Python-ImageMagick API*。OP 正在询问一个(PythonMagick),而您正在回答有关另一个(PythonMagickWand)的信息。 (31认同)