2009-11-16 13 views

Respuesta

-11

Es un fijaciones a la MagickWand API: http://www.assembla.com/wiki/show/pythonmagickwand

para que pueda utilizar todas las funciones de la API MagickWand.

#!/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() 
+26

No sé por qué esto fue aceptado, no es correcto. Hay * dos API diferentes de Python-ImageMagick *. El OP pregunta por uno (PythonMagick), y usted está respondiendo con información sobre el otro (PythonMagickWand). –

+0

Sí mi mal, yo tampoco lo sé. – Natim

31

No pude encontrarlos en ninguna parte, pero de todos modos así fue como lo usé.

Ejemplo

import PythonMagick 
image = PythonMagick.Image("sample_image.jpg") 
print image.fileName() 
print image.magick() 
print image.size().width() 
print image.size().height() 

Con salida como esta

sample_image.jpg 
JPEG 
345 
229 

Para saber qué opciones están disponibles, por ejemplo, me miraba en la fuente CPP métodos de imagen. Tomando el Imagen enlace de objetos: Imagen implementada en _Image.cpp O mejor aún mire la sugerencia para obtener los métodos contenidos en otra respuesta por Klaus en esta página.

En este archivo verá líneas de este tipo

.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) 

El bit entre comillas se asigna al nombre de la función del objeto de imagen. Siguiendo este enfoque, puedes descubrir lo suficiente para ser útil. Por ejemplo Geometría métodos específicos están en _Geometry.cpp y la incluyen los sospechosos habituales, como

 .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) 
17

Para averiguar los métodos de tipo en Python:

import PythonMagick 
dir(PythonMagick.Image()) 

, entonces obtendrá una salida como esto:

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

16

Por lo que puedo decir, PythonMagick cierra el Magick++ library. Pude copiar y pegar el código C++ usando esta biblioteca en python y funciona como se esperaba. Además, coinciden los nombres de las clases y las funciones de los miembros (mientras que MagickWand parece ser totalmente diferente).

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

Para cualquier persona que todavía está tratando de encontrar la documentación de PythonMagick, PythonMagick es exactamente el mismo que Magick ++ (API para C++). here es la documentación de Magick ++. Para algún parámetro específico, deberá encontrar el tipo y luego la enumeración (por ejemplo, gravedad-> PythonMagick.GravityType.thegravityyouwant)

Cuestiones relacionadas