PythonMagick的文档和示例
我在哪里可以找到关于 PythonMagick 的文档和示例呢?
我在谷歌上搜索了一下,但没找到太多信息。
6 个回答
要查看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']
我也找不到它们,但我还是找到了使用它的方法。
举个例子
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中实现的。或者更好的是,可以看看页面上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)
编辑:这里没什么好看的。请参考下面的更好答案 。
这是一个与 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()