【发布时间】:2010-12-16 22:40:14
【问题描述】:
在哪里可以找到PythonMagick的文档和示例?
我在 Google 上进行了搜索,但没有找到太多信息。
【问题讨论】:
-
杰克你能改变这个接受的答案吗?
-
杰克我知道你正忙于推特,除了我们试图让这个网站正常工作之外,请
标签: python imagemagick
在哪里可以找到PythonMagick的文档和示例?
我在 Google 上进行了搜索,但没有找到太多信息。
【问题讨论】:
标签: python imagemagick
编辑:这里没什么可看的。参考更好的答案below。
它是对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()
【讨论】:
PythonMagick 与 Magick++ 并不完全相同,它映射到 Magick++ 的 子集。因此,如果您开始尝试根据 C++ 文档使用它,您最终会遇到未映射的内容。 在文档不足的库上浪费了大量时间(在我作为开发人员的 30 年中)之后,我制定了一条规则: 如果没有正确记录,请不要使用它。
我最终使用 python3-PIL 完成了我需要做的事情。很遗憾,因为 ImageMagick 非常适合从 C++ 中使用。但我推荐我的规则。从长远来看,它会为您节省大量时间。
【讨论】:
对于仍在尝试查找 PythonMagick 文档的任何人,PythonMagick 与 Magick++(C++ 的 API)完全相同。 here 是 Magick++ 文档。对于某些特定参数,您需要先找到类型,然后再找到枚举(例如,gravity->PythonMagick.GravityType.thegravityyouwant)
【讨论】:
要找出 Python 中的方法类型:
import PythonMagick
dir(PythonMagick.Image())
然后你会得到这样的输出:
['__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']
【讨论】:
据我所知,PythonMagick 包装了Magick++ library。我已经能够使用这个库将 C++ 代码复制并粘贴到 python 中,并且它可以按预期工作。加上类和成员函数的名称匹配(MagickWand 似乎完全不同)。
import PythonMagick as Magick
img = Magick.Image("testIn.jpg")
img.quality(100) #full compression
img.magick('PNG')
img.write("testOut.png")
【讨论】:
我也无法在任何地方找到它们,但无论如何我都是这样使用它的。
例子
import PythonMagick
image = PythonMagick.Image("sample_image.jpg")
print image.fileName()
print image.magick()
print image.size().width()
print image.size().height()
这样的输出
sample_image.jpg
JPEG
345
229
为了找出可用的图像方法,例如,我查看了 cpp 源代码。取Image对象绑定:_Image.cpp中实现的Image 或者最好还是看看这个页面上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)
引号中的位映射到 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)
【讨论】: