Wand is a ctypes-based simple ImageMagick binding for Python.
from wand.image import Image
from wand.display import display
with Image(filename='mona-lisa.png') as img:
print(img.size)
for r in 1, 2, 3:
with img.clone() as i:
i.resize(int(i.width * r * 0.25), int(i.height * r * 0.25))
i.rotate(90 * r)
i.save(filename='mona-lisa-{0}.png'.format(r))
display(i)
You can install it from PyPI (and it requires MagickWand library):
$ apt-get install libmagickwand-dev
$ pip install Wand
There are already many MagickWand API bindings for Python, however they are lacking something we need:
This guide doesn’t cover all changes in 0.3. See also the full list of changes in Version 0.3.0.
Wand finally becomes to support Python 3, the future of Python. It actually doesn’t cover all Python 3 versions, but the most two recent versions, 3.2 and 3.3, are supported. We still support Python 2.6, 2.7, and PyPy as well, so there’s no dropped compatibility.
See also
Wand now adds supports to sequential images like animated image/gif images and image/ico images that contains multiple icons. To distinguish between each single image and the container image, newly introduced class SingleImage has been added. The most of operations and properties are commonly available for both types, Image and SingleImage, and these are defined by their common superclass, BaseImage.
So every Image object now has sequence attribute which is list-like. It implements collections.MutableSequence protocol. That means you can pass it into for statement, get an item by index from it, slice it, call len() for it, or del an item of it by index. Every item inside it is a SingleImage instance.
The following example shows you how to determine the largest icon in a image/ico file:
>>> from wand.image import Image
>>> import urllib2
>>> with Image(file=urllib2.urlopen('https://github.com/favicon.ico')) as ico:
... max(ico.sequence, key=lambda i: i.width * i.height)
...
<wand.sequence.SingleImage: 80d158d (32x32)>
This feature was initially proposed by Michael Elovskikh (#34), and then he also did initial work on this (#39). Andrey Antukh then improved its API (#66). Bear Dong and Taeho Kim did additional efforts for issues related to animated image/gif images (#88, #103, #112).
See also the guide for sequence as well: Sequence.
Wand 0.3 provides basic facilities to draw Lines or Texts.
The following example code writes “Wand” to the transparent background using caption() method:
>>> from wand.font import Font
>>> font = Font(path='tests/assets/League_Gothic.otf', size=64)
>>> with Image(width=300, height=150) as image:
... image.caption('Wand', left=5, top=5, width=490, height=140, font=font)
... image.save(filename='caption-result.png')
...
Adrian Jung and did the most of work for this (#64). Cha, Hojeong added higher-level APIs on this and more text drawing APIs (#69, #71, #74).
Wand now can read EXIF metadata from images through metadata property which is a mapping:
>>> from __future__ import print_function
>>> url = 'http://farm9.staticflickr.com/8282/7874109806_3fe0080ae4_o_d.jpg'
>>> with Image(file=urllib2.urlopen(url)) as i:
... for key, value in i.metadata.items():
... if key.startswith('exif:'):
... print(key, value)
...
exif:ApertureValue 8/1
exif:CustomRendered 0
exif:DateTime 2012:08:27 18:42:15
exif:DateTimeDigitized 2012:08:17 02:33:36
exif:DateTimeOriginal 2012:08:17 02:33:36
exif:ExifOffset 204
exif:ExifVersion 48, 50, 50, 49
exif:ExposureBiasValue 0/1
exif:ExposureMode 1
exif:ExposureProgram 1
exif:ExposureTime 1/50
...
Thanks for Michael Elovskikh who worked on this (#25, #56).
See also the guide for this as well: Reading EXIF.
ImageMagick optionally provides seam carving (also known as liquid rescaling or content-aware resizing) through MagickLiquidRescaleImage() function if it’s properly configured --with-lqr. It makes you able to magically resize images without distortion.
Wand 0.3 becomes to provide a simple method Image.liquid_rescale() which binds this API.
You can find more detail examples in its guide: Seam carving (also known as content-aware resizing).
Some channel-related APIs like wand.image.Image.channel_images, channel_depths, and composite_channel() are added in Wand 0.3.
The following example makes the overlayed image (second, composite-channel-result.jpg) from the original image (first, composite-channel.jpg):
import shutil
import urllib2
from wand.image import Image
from wand.color import Color
url = 'http://farm6.staticflickr.com/5271/5836279075_c3f8226bc1_z.jpg'
with open('composite-channel.jpg', 'wb') as f:
u = urllib2.urlopen(url)
shutil.copyfileobj(u, f)
u.close()
with Image(filename='composite-channel.jpg') as image:
with Image(background=Color('black'),
width=image.width,
height=image.height / 3) as bar:
image.composite_channel(
channel='all_channels',
image=bar,
operator='overlay',
left=0,
top=(image.height- bar.height) / 2
)
image.save(filename='composite-channel-result.jpg')
Note
The image composite-channel.jpg used in the above example is taken by Ejja Pahlevi and licensed under CC-BY-2.0. It can be found the original photography from Flickr.
Every image now has histogram attribute, which is dictionary-like. Its keys are colors that used once or more in the image, and values are are the numbers of the pixels.
For example, simply get keys() of histogram if you need its palette.
>>> url = 'http://farm7.staticflickr.com/6145/5982384872_cb1e01004e_n.jpg'
>>> with Image(file=urllib2.urlopen(url)) as image:
... palette = image.histogram.keys()
Wand itself can be installed from PyPI using easy_install or pip:
$ easy_install Wand # or
$ pip install Wand
Wand is a Python binding of ImageMagick, so you have to install it as well:
Or you can simply install Wand and its entire dependencies using the package manager of your system (it’s way convenient but the version might be outdated):
If you’re using Linux distributions based on Debian like Ubuntu, it can be easily installed using APT:
$ sudo apt-get install libmagickwand-dev
If you need SVG, WMF, OpenEXR, DjVu, and Graphviz support you have to install libmagickcore5-extra as well:
$ sudo apt-get install libmagickcore5-extra
If you’re using Linux distributions based on Redhat like Fedora or CentOS, it can be installed using Yum:
$ yum update
$ yum install ImageMagick-devel
You need one of Homebrew or MacPorts to install ImageMagick.
$ brew install imagemagick
$ sudo port install imagemagick
If your Python in not installed using MacPorts, you have to export MAGICK_HOME path as well. Because Python that is not installed using MacPorts doesn’t look up /opt/local, the default path prefix of MacPorts packages.
$ export MAGICK_HOME=/opt/local
You could build ImageMagick by yourself, but it requires a build tool chain like Visual Studio to compile it. The easiest way is simply downloading a prebuilt binary of ImageMagick for your architecture (win32 or win64).
You can download it from the following link:
http://www.imagemagick.org/download/binaries/
Choose a binary for your architecture:
Note that you have to check Install development headers and libraries for C and C++ to make Wand able to link to it.
Lastly you have to set MAGICK_HOME environment variable to the path of ImageMagick (e.g. C:\Program Files\ImageMagick-6.7.7-Q16). You can set it in Computer ‣ Properties ‣ Advanced system settings ‣ Advanced ‣ Environment Variables....
Wand itself is already packaged in Debian/Ubuntu APT repository: python-wand. You can install it using apt-get command:
$ sudo apt-get install python-wand
There are several ways to open images:
All of these operations are provided by the constructor of Image class.
The most frequently used way is just to open an image by its filename. Image‘s constructor can take the parameter named filename:
from __future__ import print_function
from wand.image import Image
with Image(filename='pikachu.png') as img:
print('width =', img.width)
print('height =', img.height)
Note
It must be passed by keyword argument exactly. Because the constructor has many parameters that are exclusive to each other.
There is a keyword argument named file as well, but don’t confuse it with filename. While filename takes a string of a filename, file takes a input stream (file-like object).
If an image to open cannot be located by a filename but can be read through input stream interface (e.g. opened by os.popen(), contained in StringIO, read by urllib2.urlopen()), it can be read by Image constructor’s file parameter. It takes all file-like objects which implements read() method:
from __future__ import print_function
from urllib2 import urlopen
from wand.image import Image
response = urlopen('https://stylesha.re/minhee/29998/images/100x100')
try:
with Image(file=response) as img:
print('format =', img.format)
print('size =', img.size)
finally:
response.close()
In the above example code, response object returned by urlopen() function has read() method, so it also can be used as an input stream for a downloaded image.
If you have just a binary string (str) of the image, you can pass it into Image constructor’s blob parameter to read:
from __future__ import print_function
from wand.image import Image
with open('pikachu.png') as f:
image_binary = f.read()
with Image(blob=image_binary) as img:
print('width =', img.width)
print('height =', img.height)
It is a way of the lowest level to read an image. There will probably not be many cases to use it.
If you have an image already and have to copy it for safe manipulation, use clone() method:
from wand.image import Image
with Image(filename='pikachu.png') as original:
with original.clone() as converted:
converted.format = 'png'
# operations on a converted image...
For some operations like format converting or cropping, there are safe methods that return a new image of manipulated result like convert() or slicing operator. So the above example code can be replaced by:
from wand.image import Image
with Image(filename='pikachu.png') as original:
with original.convert('png') as converted:
# operations on a converted image...
When it’s read from a binary string or a file object, you can explicitly give the hint which indicates file format of an image to read — optional format keyword is for that:
from wand.image import Image
with Image(blob=image_binary, format='ico') as image:
print(image.format)
New in version 0.2.1: The format parameter to Image constructor.
To open an empty image, you have to set its width and height:
from wand.image import Image
with Image(width=200, height=100) as img:
img.save(filename='200x100-transparent.png')
Its background color will be transparent by default. You can set background argument as well:
from wand.color import Color
from wand.image import Image
with Color('red') as bg:
with Image(width=200, height=100, background=bg) as img:
img.save(filename='200x100-red.png')
New in version 0.2.2: The width, height, and background parameters to Image constructor.
You can write an Image object into a file or a byte string buffer (blob) as format what you want.
If you wonder what is image’s format, use format property.
>>> image.format
'JPEG'
The format property is writable, so you can convert images by setting this property.
from wand.image import Image
with Image(filename='pikachu.png') as img:
img.format = 'jpeg'
# operations to a jpeg image...
If you want to convert an image without any changes of the original, use convert() method instead:
from wand.image import Image
with Image(filename='pikachu.png') as original:
with original.convert('jpeg') as converted:
# operations to a jpeg image...
pass
Note
Support for some of the formats are delegated to libraries or external programs. To get a complete listing of which image formats are supported on your system, use identify command provided by ImageMagick:
$ identify -list format
In order to save an image to a file, use save() method with the keyword argument filename:
from wand.image import Image
with Image(filename='pikachu.png') as img:
img.format = 'jpeg'
img.save(filename='pikachu.jpg')
You can write an image into a output stream (file-like object which implements write() method) as well. The parameter file takes a such object (it also is the first positional parameter of save() method).
For example, the following code converts pikachu.png image into JPEG, gzips it, and then saves it to pikachu.jpg.gz:
import gzip
from wand.image import Image
gz = gzip.open('pikachu.jpg.gz')
with Image(filename='pikachu.png') as img:
img.format = 'jpeg'
img.save(file=gz)
gz.close()
Want just a binary string of the image? Use make_blob() method so:
from wand.image import Image
with image(filename='pikachu.png') as img:
img.format = 'jpeg'
jpeg_bin = img.make_blob()
There’s the optional format parameter as well. So the above example code can be simpler:
from wand.image import Image
with Image(filename='pikachu.png') as img:
jpeg_bin = img.make_blob('jpeg')
Creating thumbnails (by resizing images) and cropping are most frequent works about images. This guide explains ways to deal with sizes of images.
Above all, to get the current size of the image check width and height properties:
>>> from urllib2 import urlopen
>>> from wand.image import Image
>>> f = urlopen('http://api.twitter.com/1/users/profile_image/hongminhee')
>>> with Image(file=f) as img:
... width = img.width
... height = img.height
...
>>> f.close()
>>> width
48
>>> height
48
If you want the pair of (width, height), check size property also.
Note
These three properties are all readonly.
It scales an image into a desired size even if the desired size is larger than the original size. ImageMagick provides so many algorithms for resizing. The constant FILTER_TYPES contains names of filtering algorithms.
See also
Image.resize() method takes width and height of a desired size, optional filter ('undefined' by default which means IM will try to guess best one to use) and optional blur (default is 1). It returns nothing but resizes itself in-place.
>>> img.size
(500, 600)
>>> img.resize(50, 60)
>>> img.size
(50, 60)
Although Image.resize() provides many filter options, it’s relatively slow. If speed is important for the job, you’d better use Image.sample() instead. It works in similar way to Image.resize() except it doesn’t provide filter and blur options:
>>> img.size
(500, 600)
>>> img.sample(50, 60)
>>> img.size
(50, 60)
To extract a sub-rectangle from an image, use the crop() method. It crops the image in-place. Its parameters are left, top, right, bottom in order.
>>> img.size
(200, 300)
>>> img.crop(10, 20, 50, 100)
>>> img.size
(40, 80)
It can also take keyword arguments width and height. These parameters replace right and bottom.
>>> img.size
(200, 300)
>>> img.crop(10, 20, width=40, height=80)
>>> img.size
(40, 80)
There is an another way to crop images: slicing operator. You can crop an image by [left:right, top:bottom] with maintaining the original:
>>> img.size
(300, 300)
>>> with img[10:50, 20:100] as cropped:
... print(cropped.size)
...
(40, 80)
>>> img.size
(300, 300)
Use this function to crop and resize and image at the same time, using ImageMagick geometry strings. Cropping is performed first, followed by resizing.
For example, if you want to crop your image to 300x300 pixels and then scale it by 2x for a final size of 600x600 pixels, you can call:
img.transform('300x300', '200%')
Other example calls:
# crop top left corner
img.transform('50%')
# scale height to 100px and preserve aspect ratio
img.transform(resize='x100')
# if larger than 640x480, fit within box, preserving aspect ratio
img.transform(resize='640x480>')
# crop a 320x320 square starting at 160x160 from the top left
img.transform(crop='320+160+160')
See also
New in version 0.3.0.
Seam carving is an algorithm for image resizing that functions by establishing a number of seams (paths of least importance) in an image and automatically removes seams to reduce image size or inserts seams to extend it.
In short: you can magickally resize images without distortion! See the following examples:
Original | Resized |
![]() |
![]() |
Cropped | Seam carving |
![]() |
![]() |
You can easily rescale images with seam carving using Wand: use Image.liquid_rescale() method:
>>> image = Image(filename='seam.jpg')
>>> image.size
(320, 234)
>>> with image.clone() as resize:
... resize.resize(234, 234)
... resize.save(filename='seam-resize.jpg')
... resize.size
...
(234, 234)
>>> with image[:234, :] as crop:
... crop.save(filename='seam-crop.jpg')
... crop.size
...
(234, 234)
>>> with image.clone() as liquid:
... liquid.liquid_rescale(234, 234)
... liquid.save(filename='seam-liquid.jpg')
... liquid.size
...
(234, 234)
Note
It may raise MissingDelegateError if your ImageMagick is configured --without-lqr option. In this case you should recompile ImageMagick.
See also
Note
The image seam.jpg used in the above example is taken by D. Sharon Pruitt and licensed under CC-BY-2.0. It can be found the original photography from Flickr.
Note
The image transform.jpg used in this docs is taken by Megan Trace, and licensed under CC BY-NC 2.0. It can be found the original photography from Flickr.
New in version 0.1.8.
Image object provides a simple method to rotate images: rotate(). It takes a degree which can be 0 to 359. (Actually you can pass 360, 361, or more but it will be the same to 0, 1, or more respectively.)
For example, where the given image transform.jpg:
The below code makes the image rotated 90° to right:
from wand.image import Image
with Image(filename='transform.jpg') as image:
with image.clone() as rotated:
rotated.rotate(90)
rotated.save(filename='transform-rotated-90.jpg')
The generated image transform-rotated-90.jpg looks like:
If degree is not multiples of 90, the optional parameter background will help (its default is transparent):
from wand.color import Color
from wand.image import Image
with Image(filename='transform.jpg') as image:
with image.clone() as rotated:
rotated.rotate(135, background=Color('rgb(229,221,112)'))
rotated.save(filename='transform-rotated-135.jpg')
The generated image transform-rotated-135.jpg looks like:
New in version 0.3.0.
You can make a mirror image by reflecting the pixels around the central x- or y-axis. For example, where the given image transform.jpg:
The following code flips the image using Image.flip() method:
from wand.image import Image
with Image(filename='transform.jpg') as image:
with image.clone() as flipped:
flipped.flip()
flipped.save(filename='transform-flipped.jpg')
The image transform-flipped.jpg generated by the above code looks like:
As like flip(), flop() does the same thing except it doesn’t make a vertical mirror image but horizontal:
from wand.image import Image
with Image(filename='transform.jpg') as image:
with image.clone() as flopped:
flopped.flop()
flopped.save(filename='transform-flopped.jpg')
The image transform-flopped.jpg generated by the above code looks like:
New in version 0.3.0.
The wand.drawing module provides some basic drawing functions. wand.drawing.Drawing object buffers instructions for drawing shapes into images, and then it can draw these shapes into zero or more images.
It’s also callable and takes an Image object:
from wand.drawing import Drawing
from wand.image import Image
with Drawing() as draw:
# does something with ``draw`` object,
# and then...
with Image(filename='wandtests/assets/beach.jpg') as image:
draw(image)
You can draw lines using line() method. It simply takes two (x, y) coordinates for start and end of a line. For example, the following code draws a diagonal line into the image:
draw.line((0, 0), image.size)
draw(image)
Or you can turn this diagonal line upside down:
draw.line((0, image.height), (image.width, 0))
draw(image)
The line color is determined by fill_color property, and you can change this of course. The following code draws a red diagonal line into the image:
from wand.color import Color
with Color('red') as color:
draw.fill_color = color
draw.line((0, 0), image.size)
draw(image)
New in version 0.3.6.
If you want to draw rectangles use rectangle() method. It takes left/top coordinate, and right/bottom coordinate, or width and height. For example, the following code draws a square on the image:
draw.rectangle(left=10, top=10, right=40, bottom=40)
draw(image)
Or using width and height instead of right and bottom:
draw.rectangle(left=10, top=10, width=30, height=30)
draw(image)
Note that the stoke and the fill are determined by the following properties:
Drawing object can write texts as well using its text() method. It takes x and y cordinates to be drawn and a string to write:
draw.font = 'wandtests/assets/League_Gothic.otf'
draw.font_size = 40
draw.text(image.width / 2, image.height / 2, 'Hello, world!')
draw(image)
As the above code shows you can adjust several settings before writing texts:
Every Image object has type property which identifies its colorspace. The value can be one of IMAGE_TYPES enumeration, and set of its available values depends on its format as well. For example, 'grayscale' isn’t available on JPEG.
>>> from wand.image import Image
>>> with Image(filename='wandtests/assets/bilevel.gif') as img:
... img.type
...
'bilevel'
>>> with Image(filename='wandtests/assets/sasha.jpg') as img2:
... img2.type
...
'truecolor'
You can change this value:
with Image(filename='wandtests/assets/bilevel.gif') as img:
img.type = 'truecolor'
img.save(filename='truecolor.gif')
See also
You can find whether an image has alpha channel and change it to have or not to have the alpha channel using alpha_channel property, which is preserving a bool value.
>>> with Image(filename='wandtests/assets/sasha.jpg') as img:
... img.alpha_channel
...
False
>>> with Image(filename='wandtests/assets/croptest.png') as img:
... img.alpha_channel
...
True
It’s a writable property:
with Image(filename='wandtests/assets/sasha.jpg') as img:
img.alpha_channel = True
New in version 0.3.0.
Image.metadata contains metadata of the image including EXIF. These are prefixed by 'exif:' e.g. 'exif:ExifVersion', 'exif:Flash'.
Here’s a straightforward example to access EXIF of an image:
exif = {}
with Image(filename='wandtests/assets/beach.jpg') as image:
exif.update((k[5:], v) for k, v in image.metadata.items()
if k.startswith('exif:'))
Note
You can’t write into Image.metadata.
Note
The image sequence-animation.gif used in this docs has been released into the public domain by its author, C6541 at Wikipedia project. This applies worldwide. (Source)
New in version 0.3.0.
Some images may actually consist of two or more images. For example, animated image/gif images consist of multiple frames. Some image/ico images have different sizes of icons.
For example, the above image sequence-animation.gif consists of the following frames (actually it has 60 frames, but we sample only few frames to show here):
If we open this image, Image object has sequence. It’s a list-like object that maintain its all frames.
For example, len() for this returns the number of frames:
>>> from wand.image import Image
>>> with Image(filename='sequence-animation.gif') as image:
... len(image.sequence)
...
60
You can get an item by index from sequence:
>>> with Image(filename='sequence-animation.gif') as image:
... image.sequence[0]
...
<wand.sequence.SingleImage: ed84c1b (256x256)>
Or slice it:
>>> with Image(filename='sequence-animation.gif') as image:
... image.sequence[5:10]
...
[<wand.sequence.SingleImage: 0f49491 (256x256)>,
<wand.sequence.SingleImage: 8eba0a5 (256x256)>,
<wand.sequence.SingleImage: 98c10fa (256x256)>,
<wand.sequence.SingleImage: b893194 (256x256)>,
<wand.sequence.SingleImage: 181ce21 (256x256)>]
Note that each item of sequence is a SingleImage instance, not Image.
Image is a container that directly represents image files like sequence-animation.gif, and SingleImage is a single image that represents frames in animations or sizes in image/ico files.
They both inherit BaseImage, the common abstract class. They share the most of available operations and properties like resize() and size, but some are not. For example, save() and mimetype are only provided by Image. delay and index are only available for SingleImage.
In most cases, images don’t have multiple images, so it’s okay if you think that Image and SingleImage are the same, but be careful when you deal with animated image/gif files or image/ico files that contain multiple icons.
See also
Objects Wand provides are resources to be managed. It has to be closed (destroyed) after using like file or database connection. You can deal with it using with very easily and explicitly:
with Image(filename='') as img:
# deal with img...
Or you can call its destroy() (or close() if it is an Image instance) method manually:
try:
img = Image(filename='')
# deal with img...
finally:
img.destroy()
Note
It also implements the destructor that invokes destroy(), and if your program runs on CPython (which does reference counting instead of ordinary garbage collection) most of resources are automatically deallocated.
However it’s just depending on CPython’s implementation detail of memory management, so it’s not a good idea. If your program runs on PyPy (which implements garbage collector) for example, invocation time of destructors is not determined, so the program would be broken.
Wand has unit tests and regression tests. It can be run using setup.py script:
$ python setup.py test
It uses pytest as its testing library. The above command will automatically install pytest as well if it’s not installed yet.
Or you can manually install pytest and then use py.test command. It provides more options:
$ pip install pytest
$ py.test
There are some time-consuming tests. You can skip these tests using --skip-slow option:
$ py.test --skip-slow
You can run only tests you want using -k option.
$ py.test -k image
Wand should be compatible with various Python implementations including CPython 2.6, 2.7, PyPy. tox is a testing software that helps Python packages to test on various Python implementations at a time.
It can be installed using easy_install or pip:
$ easy_install tox
If you type just tox at Wand directory it will be tested on multiple Python interpreters:
$ tox
GLOB sdist-make: /Users/dahlia/Desktop/wand/setup.py
py26 create: /Users/dahlia/Desktop/wand/.tox/py26
py26 installdeps: pytest
py26 sdist-inst: /Users/dahlia/Desktop/wand/.tox/dist/Wand-0.2.2.zip
py26 runtests: commands[0]
...
You can use a double -- to pass options to pytest:
$ tox -- -k sequence
Travis CI automatically builds and tests every commit and pull request. The above banner image shows the current status of Wand build. You can see the detail of the current status from the following URL:
PIL has very long history and the most of Python projects still depend on it. We will work on PIL compatibility layer using Wand. It will provide two ways to emulate PIL:
Module-level compatibility which can be used by changing import:
try:
from wand.pilcompat import Image
except ImportError:
from PIL import Image
Global monkeypatcher which changes sys.modules:
from wand.pilcompat.monkey import patch; patch()
import PIL.Image # it imports wand.pilcompat.Image module
Primary interface of ImageMagick is convert command. It provides a small parameter language, and many answers on the Web contain code using this. The problem is that you can’t simply copy-and-paste these code to utilize Wand.
This feature is to make these CLI codes possible to be used with Wand.
It makes numpy.asarray() able to take Image object to deal with its pixels as matrix.
Its branch name will be numpy.
Released on December 20, 2014.
Released on August 3, 2014.
Released on March 23, 2014.
Released on September 13, 2013.
Released on September 9, 2013.
Released on August 4, 2013. It’s author’s birthday.
Released on July 11, 2013.
Released on June 17, 2013.
See also
Released on May 28, 2013.
Released on January 25, 2013.
Released on September 24, 2012.
Released on August 19, 2012. Beta version.
Released on June 20, 2012. Alpha version.
Released on May 8, 2012. Still alpha version.
Released on December 23, 2011. Still alpha version.
Released on December 2, 2011. Still alpha version.
Released on November 10, 2011. Still alpha version.
Released on October 31, 2011. Still alpha version.
Released on October 28, 2011. Slightly mature alpha version.
Released on October 27, 2011. Hotfix of the malformed Python package.
Released on October 27, 2011. Slightly mature alpha version.
Released on October 16, 2011. Still alpha version.
Released on October 4, 2011. Still alpha version.
Released on October 1, 2011. Very alpha version.
Opens and manipulates images. Image objects can be used in with statement, and these resources will be automatically managed (even if any error happened):
with Image(filename='pikachu.png') as i:
print('width =', i.width)
print('height =', i.height)
(tuple) The list of alpha channel types
See also
(dict) The dictionary of channel types.
See also
(tuple) The list of colorspaces.
See also
New in version 0.3.4.
(tuple) The list of composition operators
Changed in version 0.3.0: Renamed from COMPOSITE_OPS to COMPOSITE_OPERATORS.
See also
(tuple) The list of evaluation operators
See also
(tuple) The list of filter types.
See also
(tuple) The list of gravity types.
New in version 0.3.0.
(tuple) The list of image types
See also
(tuple) The list of orientation types.
New in version 0.3.0.
(tuple) The list of resolution unit types.
See also
The abstract base of Image (container) and SingleImage. That means the most of operations, defined in this abstract classs, are possible for both Image and SingleImage.
New in version 0.3.0.
(bool) Get state of image alpha channel. It can also be used to enable/disable alpha channel.
New in version 0.2.1.
(bool) Whether the image is animation or not. It doesn’t only mean that the image has two or more images (frames), but all frames are even the same size. It’s about image format, not content. It’s False even if image/ico consits of two or more images of the same size.
For example, it’s False for image/jpeg, image/gif, image/ico.
If image/gif has two or more frames, it’s True. If image/gif has only one frame, it’s False.
New in version 0.3.0.
Changed in version 0.3.8: Became to accept image/x-gif as well.
(wand.color.Color) The image background color. It can also be set to change the background color.
New in version 0.1.9.
Writes a caption text into the position.
Parameters: |
|
---|
New in version 0.3.0.
Clones the image. It is equivalent to call Image with image parameter.
with img.clone() as cloned:
# manipulate the cloned image
pass
Returns: | the cloned new image |
---|---|
Return type: | Image |
New in version 0.1.1.
(basestring) The image colorspace.
Defines image colorspace as in COLORSPACE_TYPES enumeration.
It may raise ValueError when the colorspace is unknown.
New in version 0.3.4.
Places the supplied image over the current image, with the top left corner of image at coordinates left, top of the current image. The dimensions of the current image are not changed.
Parameters: |
|
---|
New in version 0.2.0.
Composite two images using the particular channel.
Parameters: |
|
---|---|
Raises exceptions.ValueError: | |
when the given channel or operator is invalid |
New in version 0.3.0.
(numbers.Integral) Compression quality of this image.
New in version 0.2.0.
Crops the image in-place.
+--------------------------------------------------+
| ^ ^ |
| | | |
| top | |
| | | |
| v | |
| <-- left --> +-------------------+ bottom |
| | ^ | | |
| | <-- width --|---> | | |
| | height | | |
| | | | | |
| | v | | |
| +-------------------+ v |
| <--------------- right ----------> |
+--------------------------------------------------+
Parameters: |
|
---|---|
Raises exceptions.ValueError: | |
when one or more arguments are invalid |
Note
If you want to crop the image but not in-place, use slicing operator.
Changed in version 0.1.8: Made to raise ValueError instead of IndexError for invalid width/height arguments.
New in version 0.1.7.
(numbers.Integral) The depth of this image.
New in version 0.2.1.
Creates a vertical mirror image by reflecting the pixels around the central x-axis. It manipulates the image in place.
New in version 0.3.0.
Creates a horizontal mirror image by reflecting the pixels around the central y-axis. It manipulates the image in place.
New in version 0.3.0.
(wand.font.Font) The current font options.
(basestring) The path of the current font. It also can be set.
(numbers.Real) The font size. It also can be set.
Blurs the image. We convolve the image with a gaussian operator of the given radius and standard deviation (sigma). For reasonable results, the radius should be larger than sigma. Use a radius of 0 and blur() selects a suitable radius for you.
Parameters: |
|
---|
New in version 0.3.3.
(basestring) The text placement gravity used when annotating with text. It’s a string from GRAVITY_TYPES list. It also can be set.
(numbers.Integral) The height of this image.
(HistogramDict) The mapping that represents the histogram. Keys are Color objects, and values are the number of pixels.
New in version 0.3.0.
Rescales the image with seam carving, also known as image retargeting, content-aware resizing, or liquid rescaling.
Parameters: |
|
---|---|
Raises wand.exceptions.MissingDelegateError: | |
when ImageMagick isn’t configured --with-lqr option. |
Note
This feature requires ImageMagick to be configured --with-lqr option. Or it will raise MissingDelegateError:
See also
Changes the brightness, saturation and hue of an image. We modulate the image with the given brightness, saturation and hue.
Parameters: |
|
---|---|
Raises exceptions.ValueError: | |
when one or more arguments are invalid |
New in version 0.3.4.
Negate the colors in the reference image.
Parameters: |
---|
New in version 0.3.8.
(OptionDict) The mapping of internal option settings.
New in version 0.3.0.
Changed in version 0.3.4: Added 'jpeg:sampling-factor' option.
Changed in version 0.3.9: Added 'pdf:use-cropbox' option.
(basestring) The image orientation. It’s a string from ORIENTATION_TYPES list. It also can be set.
New in version 0.3.0.
(int) The maxumim value of a color channel that is supported by the imagemagick library.
New in version 0.2.0.
Reset the coordinate frame of the image so to the upper-left corner is (0, 0) again (crop and rotate operations change it).
New in version 0.2.0.
Resizes the image.
Parameters: |
|
---|
Changed in version 0.2.1: The default value of filter has changed from 'triangle' to 'undefined' instead.
Changed in version 0.1.8: The blur parameter changed to take numbers.Real instead of numbers.Rational.
New in version 0.1.1.
(tuple) Resolution of this image.
New in version 0.3.0.
Rotates the image right. It takes a background color for degree that isn’t a multiple of 90.
Parameters: |
|
---|
New in version 0.2.0: The reset_coords parameter.
New in version 0.1.8.
Resizes the image by sampling the pixels. It’s basically quicker than resize() except less quality as a tradeoff.
Parameters: |
|
---|
New in version 0.3.4.
(collections.Sequence) The list of SingleImages that the image contains.
New in version 0.3.0.
Transforms the image using MagickTransformImage(), which is a convenience function accepting geometry strings to perform cropping and resizing. Cropping is performed first, followed by resizing. Either or both arguments may be omitted or given an empty string, in which case the corresponding action will not be performed. Geometry specification strings are defined as follows:
A geometry string consists of a size followed by an optional offset. The size is specified by one of the options below, where bold terms are replaced with appropriate integer values:
The offset, which only applies to the cropping geometry string, is given by {+-}x{+-}y, that is, one plus or minus sign followed by an x offset, followed by another plus or minus sign, followed by a y offset. Offsets are in pixels from the upper left corner of the image. Negative offsets will cause the corresponding number of pixels to be removed from the right or bottom edge of the image, meaning the cropped size will be the computed size minus the absolute value of the offset.
For example, if you want to crop your image to 300x300 pixels and then scale it by 2x for a final size of 600x600 pixels, you can call:
image.transform('300x300', '200%')
This method is a fairly thing wrapper for the C API, and does not perform any additional checking of the parameters except insofar as verifying that they are of the correct type. Thus, like the C API function, the method is very permissive in terms of what it accepts for geometry strings; unrecognized strings and trailing characters will be ignored rather than raising an error.
Parameters: |
|
---|
See also
New in version 0.2.2.
Makes the color color a transparent color with a tolerance of fuzz. The alpha parameter specify the transparency level and the parameter fuzz specify the tolerance.
Parameters: |
|
---|
New in version 0.3.0.
Makes the image transparent by subtracting some percentage of the black color channel. The transparency parameter specifies the percentage.
Parameters: | transparency (numbers.Real) – the percentage fade that should be performed on the image, from 0.0 to 1.0 |
---|
New in version 0.2.0.
(basestring) The image type.
Defines image type as in IMAGE_TYPES enumeration.
It may raise ValueError when the type is unknown.
New in version 0.2.2.
(basestring) The resolution units of this image.
Sharpens the image using unsharp mask filter. We convolve the image with a Gaussian operator of the given radius and standard deviation (sigma). For reasonable results, radius should be larger than sigma. Use a radius of 0 and unsharp_mask()`() selects a suitable radius for you.
Parameters: |
|
---|
New in version 0.3.4.
Internal pointer to the MagickWand instance. It may raise ClosedImageError when the instance has destroyed already.
Transparentized the supplied image and places it over the current image, with the top left corner of image at coordinates left, top of the current image. The dimensions of the current image are not changed.
Parameters: |
|
---|
New in version 0.2.0.
(numbers.Integral) The width of this image.
The mapping table of channels to their depth.
Parameters: | image (Image) – an image instance |
---|
Note
You don’t have to use this by yourself. Use Image.channel_depths property instead.
New in version 0.3.0.
The mapping table of separated images of the particular channel from the image.
Parameters: | image (Image) – an image instance |
---|
Note
You don’t have to use this by yourself. Use Image.channel_images property instead.
New in version 0.3.0.
An error that rises when some code tries access to an already closed image.
Specialized mapping object to represent color histogram. Keys are colors, and values are the number of pixels.
Parameters: | image (BaseImage) – the image to get its histogram |
---|
New in version 0.3.0.
An image object.
Parameters: |
|
---|
New in version 0.1.5: The file parameter.
New in version 0.1.1: The blob parameter.
New in version 0.2.1: The format parameter.
New in version 0.2.2: The width, height, background parameters.
New in version 0.3.0: The resolution parameter.
Crops the image by its left, right, top and bottom, and then returns the cropped one.
with img[100:200, 150:300] as cropped:
# manipulated the cropped image
pass
Like other subscriptable objects, default is 0 or its width/height:
img[:, :] #--> just clone
img[:100, 200:] #--> equivalent to img[0:100, 200:img.height]
Negative integers count from the end (width/height):
img[-70:-50, -20:-10]
#--> equivalent to img[width-70:width-50, height-20:height-10]
Returns: | the cropped image |
---|---|
Rtype: | Image |
New in version 0.1.2.
Creates blank image.
Parameters: |
|
---|---|
Returns: | blank image |
Return type: |
New in version 0.3.0.
Surrounds the image with a border.
Parameters: |
|
---|
New in version 0.3.0.
(ChannelDepthDict) The mapping of channels to their depth. Read only.
New in version 0.3.0.
(ChannelImageDict) The mapping of separated channels from the image.
with image.channel_images['red'] as red_image:
display(red_image)
Clears resources associated with the image, leaving the image blank, and ready to be used with new image.
New in version 0.3.0.
Closes the image explicitly. If you use the image object in with statement, it was called implicitly so don’t have to call it.
Note
It has the same functionality of destroy() method.
(basestring) The type of image compression. It’s a string from COMPRESSION_TYPES list. It also can be set.
New in version 0.3.6.
Converts the image format with the original image maintained. It returns a converted image instance which is new.
with img.convert('png') as converted:
converted.save(filename='converted.png')
Parameters: | format (basestring) – image format to convert to |
---|---|
Returns: | a converted image |
Return type: | Image |
Raises: | ValueError when the given format is unsupported |
New in version 0.1.6.
(basestring) The image format.
If you want to convert the image format, just reset this property:
assert isinstance(img, wand.image.Image)
img.format = 'png'
It may raise ValueError when the format is unsupported.
See also
New in version 0.1.6.
Makes the binary string of the image.
Parameters: | format (basestring) – the image format to write e.g. 'png', 'jpeg'. it is omittable |
---|---|
Returns: | a blob (bytes) string |
Return type: | str |
Raises: | ValueError when format is invalid |
Changed in version 0.1.6: Removed a side effect that changes the image format silently.
New in version 0.1.5: The format parameter became optional.
New in version 0.1.1.
(basestring) The MIME type of the image e.g. 'image/jpeg', 'image/png'.
New in version 0.1.7.
Normalize color channels.
Parameters: | channel (basestring) – the channel type. available values can be found in the CHANNELS mapping. If None, normalize all channels. |
---|
Read new image into Image() object.
Parameters: |
|
---|
New in version 0.3.0.
Saves the image into the file or filename. It takes only one argument at a time.
Parameters: |
|
---|
New in version 0.1.5: The file parameter.
New in version 0.1.1.
Strips an image of all profiles and comments.
New in version 0.2.0.
Remove solid border from image. Uses top left pixel as a guide by default, or you can also specify the color to remove.
Parameters: |
|
---|
New in version 0.3.0: Optional color and fuzz parameters.
New in version 0.2.1.
The mixin class to maintain a weak reference to the parent Image object.
New in version 0.3.0.
(Image) The parent image.
It ensures that the parent Image, which is held in a weak reference, still exists. Returns the dereferenced Image if it does exist, or raises a ClosedImageError otherwise.
Exc: | ClosedImageError when the parent Image has been destroyed |
---|
Row iterator for Image. It shouldn’t be instantiated directly; instead, it can be acquired through Image instance:
assert isinstance(image, wand.image.Image)
iterator = iter(image)
It doesn’t iterate every pixel, but rows. For example:
for row in image:
for col in row:
assert isinstance(col, wand.color.Color)
print(col)
Every row is a collections.Sequence which consists of one or more wand.color.Color values.
Parameters: | image (Image) – the image to get an iterator |
---|
New in version 0.1.3.
Clones the same iterator.
Class that implements dict-like read-only access to image metadata like EXIF or IPTC headers.
Parameters: | image (Image) – an image instance |
---|
Note
You don’t have to use this by yourself. Use Image.metadata property instead.
New in version 0.3.0.
Mutable mapping of the image internal options. See available options in OPTIONS constant.
New in version 0.3.0.
Mark the operation manipulating itself instead of returning new one.
New in version 0.1.2.
Color value.
Unlike any other objects in Wand, its resource management can be implicit when it used outside of with block. In these case, its resource are allocated for every operation which requires a resource and destroyed immediately. Of course it is inefficient when the operations are much, so to avoid it, you should use color objects inside of with block explicitly e.g.:
red_count = 0
with Color('#f00') as red:
with Image(filename='image.png') as img:
for row in img:
for col in row:
if col == red:
red_count += 1
Parameters: | string (basestring) – a color namel string e.g. 'rgb(255, 255, 255)', '#fff', 'white'. see ImageMagick Color Names doc also |
---|
Changed in version 0.3.0: Color objects become hashable.
See also
Equality operator.
Param other: | a color another one |
---|---|
Type color: | Color |
Returns: | True only if two images equal. |
Rtype: | bool |
(numbers.Real) Alpha value, from 0.0 to 1.0.
(numbers.Integral) Alpha value as 8bit integer which is a common style. From 0 to 255.
New in version 0.3.0.
(numbers.Integral) Alpha value. Scale depends on QUANTUM_DEPTH.
New in version 0.3.0.
(numbers.Real) Blue, from 0.0 to 1.0.
(numbers.Integral) Blue as 8bit integer which is a common style. From 0 to 255.
New in version 0.3.0.
(numbers.Integral) Blue. Scale depends on QUANTUM_DEPTH.
New in version 0.3.0.
Raw level version of equality test function for two pixels.
Parameters: |
|
---|---|
Returns: | True only if two pixels equal |
Return type: |
Note
It’s only for internal use. Don’t use it directly. Use == operator of Color instead.
(numbers.Real) Green, from 0.0 to 1.0.
(numbers.Integral) Green as 8bit integer which is a common style. From 0 to 255.
New in version 0.3.0.
(numbers.Integral) Green. Scale depends on QUANTUM_DEPTH.
New in version 0.3.0.
(basestring) The normalized string representation of the color. The same color is always represented to the same string.
New in version 0.3.0.
(numbers.Real) Red, from 0.0 to 1.0.
(numbers.Integral) Red as 8bit integer which is a common style. From 0 to 255.
New in version 0.3.0.
(numbers.Integral) Red. Scale depends on QUANTUM_DEPTH.
New in version 0.3.0.
(basestring) The string representation of the color.
Straightforward port of ScaleQuantumToChar() inline function.
Parameters: | quantum (numbers.Integral) – quantum value |
---|---|
Returns: | 8bit integer of the given quantum value |
Return type: | numbers.Integral |
New in version 0.3.0.
New in version 0.3.0.
Font is an object which takes the path of font file, size, color, and whether to use antialiasing. If you want to use font by its name rather than the file path, use TTFQuery package. The font path resolution by its name is a very complicated problem to achieve.
See also
TTFQuery builds on the FontTools-TTX package to allow the Python programmer to accomplish a number of tasks:
Font struct which is a subtype of tuple.
Parameters: |
|
---|
Changed in version 0.3.9: The size parameter becomes optional. Its default value is 0, which means autosized.
(wand.color.Color) The font color.
(basestring) The path of font file.
(numbers.Real) The font size in pixels.
The module provides some vector drawing functions.
New in version 0.3.0.
(collections.Sequence) The attribute names of font metrics.
(collections.Sequence) The list of text align types.
(collections.Sequence) The list of text decoration types.
(collections.Sequence) The list of text gravity types.
Drawing object. It maintains several vector drawing instructions and can get drawn into zero or more Image objects by calling it.
For example, the following code draws a diagonal line to the image:
with Drawing() as draw:
draw.line((0, 0), image.size)
draw(image)
Parameters: | drawing (Drawing) – an optional drawing object to clone. use clone() method rathan than this parameter |
---|
New in version 0.3.0.
Renders the current drawing into the image. You can simply call Drawing instance rather than calling this method. That means the following code which calls Drawing object itself:
drawing(image)
is equivalent to the following code which calls draw() method:
drawing.draw(image)
Parameters: | image (Image) – the image to be drawn |
---|
(basestring) The current font name. It also can be set.
(numbers.Real) The font size. It also can be set.
Queries font metrics from the given text.
Parameters: |
|
---|
(basestring) The text placement gravity used when annotating with text. It’s a string from GRAVITY_TYPES list. It also can be set.
Draws a line start to end.
Parameters: |
|
---|
Draws a rectangle using the current stoke_color, stroke_width, and fill_color.
+--------------------------------------------------+
| ^ ^ |
| | | |
| top | |
| | | |
| v | |
| <-- left --> +-------------------+ bottom |
| | ^ | | |
| | <-- width --|---> | | |
| | height | | |
| | | | | |
| | v | | |
| +-------------------+ v |
| <--------------- right ----------> |
+--------------------------------------------------+
Parameters: |
|
---|
New in version 0.3.6.
(numbers.Real) The stroke width. It also can be set.
New in version 0.3.3.
Writes a text body into (x, y).
Parameters: |
|
---|
(basestring) The current text alignment setting. It’s a string value from TEXT_ALIGN_TYPES list. It also can be set.
(bool) The boolean value which represents whether antialiasing is used for text rendering. It also can be set to True or False to switch the setting.
(basestring) The text decoration setting, a string from TEXT_DECORATION_TYPES list. It also can be set.
(basestring) The internally used text encoding setting. Although it also can be set, but it’s not encorouged.
(numbers.Real) The setting of the text line spacing. It also can be set.
(numbers.Real) The setting of the word spacing. It also can be set.
(numbers.Real) The setting of the text kerning. It also can be set.
The tuple subtype which consists of font metrics data.
Alias for field number 2
Alias for field number 1
Alias for field number 0
Alias for field number 3
Alias for field number 6
Alias for field number 5
Alias for field number 4
Alias for field number 11
Alias for field number 7
Alias for field number 9
Alias for field number 12
Alias for field number 8
Alias for field number 10
New in version 0.3.0.
The list-like object that contains every SingleImage in the Image container. It implements collections.Sequence prototocol.
New in version 0.3.0.
(numbers.Integral) The current index of its internal iterator.
Note
It’s only for internal use.
Scoped setter of current_index. Should be used for with statement e.g.:
with image.sequence.index_context(3):
print(image.size)
Note
It’s only for internal use.
Each single image in Image container. For example, it can be a frame of GIF animation.
Note that all changes on single images are invinsilble to their containers until they are close()d (destroy()ed).
New in version 0.3.0.
(wand.image.Image) The container image.
(numbers.Integral) The delay to pause before display the next image (in the sequence of its container). It’s hundredths of a second.
(numbers.Integral) The index of the single image in the container image.
There is the global resource to manage in MagickWand API. This module implements automatic global resource management through reference counting.
Instantiates the MagickWand API.
Warning
Don’t call this function directly. Use increment_refcount() and decrement_refcount() functions instead.
Cleans up the MagickWand API.
Warning
Don’t call this function directly. Use increment_refcount() and decrement_refcount() functions instead.
Increments the reference_count and instantiates the MagickWand API if it is the first use.
Decrements the reference_count and cleans up the MagickWand API if it will be no more used.
Abstract base class for MagickWand object that requires resource management. Its all subclasses manage the resource semiautomatically and support with statement as well:
with Resource() as resource:
# use the resource...
pass
It doesn’t implement constructor by itself, so subclasses should implement it. Every constructor should assign the pointer of its resource data into resource attribute inside of with allocate() context. For example:
class Pizza(Resource):
'''My pizza yummy.'''
def __init__(self):
with self.allocate():
self.resource = library.NewPizza()
New in version 0.1.2.
Allocates the memory for the resource explicitly. Its subclasses should assign the created resource into resource attribute inside of this context. For example:
with resource.allocate():
resource.resource = library.NewResource()
(ctypes.CFUNCTYPE) The ctypes function that clears an exception of the resource.
Note
It is an abstract attribute that has to be implemented in the subclass.
(ctypes.CFUNCTYPE) The ctypes function that destroys the resource.
Note
It is an abstract attribute that has to be implemented in the subclass.
(ctypes.CFUNCTYPE) The ctypes function that gets an exception from the resource.
Note
It is an abstract attribute that has to be implemented in the subclass.
(ctypes.CFUNCTYPE) The ctypes predicate function that returns whether the given pointer (that contains a resource data usuaully) is a valid resource.
Note
It is an abstract attribute that has to be implemented in the subclass.
Cleans up the resource explicitly. If you use the resource in with statement, it was called implicitly so have not to call it.
Gets a current exception instance.
Returns: | a current exception. it can be None as well if any errors aren’t occurred |
---|---|
Return type: | wand.exceptions.WandException |
Raises an exception or warning if it has occurred.
Internal pointer to the resource instance. It may raise DestroyedResourceError when the resource has destroyed already.
An error that rises when some code tries access to an already destroyed resource.
Changed in version 0.3.0: It becomes a subtype of wand.exceptions.WandException.
This module maps MagickWand API’s errors and warnings to Python’s native exceptions and warnings. You can catch all MagickWand errors using Python’s natural way to catch errors.
See also
New in version 0.1.1.
Bases: wand.exceptions.WandError, exceptions.IOError
A binary large object could not be allocated, read, or written.
Bases: wand.exceptions.WandFatalError, exceptions.IOError
A binary large object could not be allocated, read, or written.
Bases: wand.exceptions.WandWarning, exceptions.IOError
A binary large object could not be allocated, read, or written.
(list) The list of (base_class, suffix) pairs (for each code). It would be zipped with DOMAIN_MAP pairs’ last element.
Bases: wand.exceptions.WandError
Pixels could not be read or written to the pixel cache.
Bases: wand.exceptions.WandFatalError
Pixels could not be read or written to the pixel cache.
Bases: wand.exceptions.WandWarning
Pixels could not be read or written to the pixel cache.
Bases: wand.exceptions.WandError
There was a problem with an image coder.
Bases: wand.exceptions.WandFatalError
There was a problem with an image coder.
Bases: wand.exceptions.WandWarning
There was a problem with an image coder.
Bases: wand.exceptions.WandError
There was a problem getting a configuration file.
Bases: wand.exceptions.WandFatalError
There was a problem getting a configuration file.
Bases: wand.exceptions.WandWarning
There was a problem getting a configuration file.
Bases: wand.exceptions.WandError, exceptions.ValueError
The image file may be corrupt.
Bases: wand.exceptions.WandFatalError, exceptions.ValueError
The image file may be corrupt.
Bases: wand.exceptions.WandWarning, exceptions.ValueError
The image file may be corrupt.
(list) A list of error/warning domains, these descriptions and codes. The form of elements is like: (domain name, description, codes).
Bases: wand.exceptions.WandError
An ImageMagick delegate failed to complete.
Bases: wand.exceptions.WandFatalError
An ImageMagick delegate failed to complete.
Bases: wand.exceptions.WandWarning
An ImageMagick delegate failed to complete.
Bases: wand.exceptions.WandError
A drawing operation failed.
Bases: wand.exceptions.WandFatalError
A drawing operation failed.
Bases: wand.exceptions.WandWarning
A drawing operation failed.
Bases: wand.exceptions.WandError, exceptions.IOError
The image file could not be opened for reading or writing.
Bases: wand.exceptions.WandFatalError, exceptions.IOError
The image file could not be opened for reading or writing.
Bases: wand.exceptions.WandWarning, exceptions.IOError
The image file could not be opened for reading or writing.
Bases: wand.exceptions.WandError
The operation could not complete due to an incompatible image.
Bases: wand.exceptions.WandFatalError
The operation could not complete due to an incompatible image.
Bases: wand.exceptions.WandWarning
The operation could not complete due to an incompatible image.
Bases: wand.exceptions.WandError, exceptions.ImportError
The image type can not be read or written because the appropriate; delegate is missing.
Bases: wand.exceptions.WandFatalError, exceptions.ImportError
The image type can not be read or written because the appropriate; delegate is missing.
Bases: wand.exceptions.WandWarning, exceptions.ImportError
The image type can not be read or written because the appropriate; delegate is missing.
Bases: wand.exceptions.WandError
There was a problem with an image module.
Bases: wand.exceptions.WandFatalError
There was a problem with an image module.
Bases: wand.exceptions.WandWarning
There was a problem with an image module.
Bases: wand.exceptions.WandError
There was a problem activating the progress monitor.
Bases: wand.exceptions.WandFatalError
There was a problem activating the progress monitor.
Bases: wand.exceptions.WandWarning
There was a problem activating the progress monitor.
Bases: wand.exceptions.WandError
A command-line option was malformed.
Bases: wand.exceptions.WandFatalError
A command-line option was malformed.
Bases: wand.exceptions.WandWarning
A command-line option was malformed.
Bases: wand.exceptions.WandError
A policy denies access to a delegate, coder, filter, path, or resource.
Bases: wand.exceptions.WandFatalError
A policy denies access to a delegate, coder, filter, path, or resource.
Bases: wand.exceptions.WandWarning
A policy denies access to a delegate, coder, filter, path, or resource.
Bases: wand.exceptions.WandError
There is a problem generating a true or pseudo-random number.
Bases: wand.exceptions.WandFatalError
There is a problem generating a true or pseudo-random number.
Bases: wand.exceptions.WandWarning
There is a problem generating a true or pseudo-random number.
Bases: wand.exceptions.WandError
There was a problem getting or setting the registry.
Bases: wand.exceptions.WandFatalError
There was a problem getting or setting the registry.
Bases: wand.exceptions.WandWarning
There was a problem getting or setting the registry.
Bases: wand.exceptions.WandError, exceptions.MemoryError
A program resource is exhausted e.g. not enough memory.
Bases: wand.exceptions.WandFatalError, exceptions.MemoryError
A program resource is exhausted e.g. not enough memory.
Bases: wand.exceptions.WandWarning, exceptions.MemoryError
A program resource is exhausted e.g. not enough memory.
Bases: wand.exceptions.WandError, exceptions.IOError
There was a problem reading or writing from a stream.
Bases: wand.exceptions.WandFatalError, exceptions.IOError
There was a problem reading or writing from a stream.
Bases: wand.exceptions.WandWarning, exceptions.IOError
There was a problem reading or writing from a stream.
(dict) The dictionary of (code, exc_type).
Bases: wand.exceptions.WandError
A font is unavailable; a substitution may have occurred.
Bases: wand.exceptions.WandFatalError
A font is unavailable; a substitution may have occurred.
Bases: wand.exceptions.WandWarning
A font is unavailable; a substitution may have occurred.
Bases: wand.exceptions.WandError
There was a problem specific to the MagickWand API.
Bases: exceptions.Exception
All Wand-related exceptions are derived from this class.
Bases: wand.exceptions.WandFatalError
There was a problem specific to the MagickWand API.
Bases: wand.exceptions.WandException
Base class for Wand-related ImageMagick version errors.
New in version 0.3.2.
Bases: wand.exceptions.WandWarning
There was a problem specific to the MagickWand API.
Bases: wand.exceptions.WandError
An X resource is unavailable.
Bases: wand.exceptions.WandFatalError
An X resource is unavailable.
Bases: wand.exceptions.WandWarning
An X resource is unavailable.
Changed in version 0.1.10: Changed to throw ImportError instead of AttributeError when the shared library fails to load.
This subclass prevents the automatic conversion behavior of ctypes.c_char_p, allowing memory to be properly freed in the destructor. It must only be used for non-const character pointers returned by ImageMagick functions.
(ctypes.CDLL) The MagickWand library.
(ctypes.CDLL) The C standard library.
(ctypes.CDLL) The ImageMagick library. It is the same with library on platforms other than Windows.
New in version 0.1.10.
Loads the MagickWand library.
Returns: | the MagickWand library and the ImageMagick library |
---|---|
Return type: | ctypes.CDLL |
This module provides several subtle things to support multiple Python versions (2.6, 2.7, 3.2, 3.3) and VM implementations (CPython, PyPy).
Makes string to str in Python 2. Makes string to bytes in Python 3.
Parameters: |
|
---|
(type) Type for representing binary data. str in Python 2 and bytes in Python 3.
alias of str
If filename is a text_type, encode it to binary_type according to filesystem’s default encoding.
(type, tuple) Types for file objects that have fileno().
Combine multiple context managers into a single nested context manager.
This function has been deprecated in favour of the multiple manager form of the with statement.
The one advantage of this function over the multiple manager form of the with statement is that argument unpacking allows it to be used with a variable number of context managers as follows:
- with nested(*managers):
- do_something()
(type) Type for text data. basestring in Python 2 and str in Python 3.
alias of basestring
Makes string to str in Python 3. Does nothing in Python 2.
Parameters: | string (bytes, str, unicode) – a string to cast it to text_type |
---|
The display() functions shows you the image. It is useful for debugging.
If you are in Mac, the image will be opened by your default image application (Preview.app usually).
If you are in Windows, the image will be opened by imdisplay.exe, or your default image application (Windows Photo Viewer usually) if imdisplay.exe is unavailable.
You can use it from CLI also. Execute wand.display module through python -m option:
$ python -m wand.display wandtests/assets/mona-lisa.jpg
New in version 0.1.9.
You can find the current version in the command line interface:
$ python -m wand.version
0.3.9
$ python -m wand.version --verbose
Wand 0.3.9
ImageMagick 6.7.7-6 2012-06-03 Q16 http://www.imagemagick.org
New in version 0.2.0: The command line interface.
New in version 0.2.2: The --verbose/-v option which also prints ImageMagick library version for CLI.
(basestring) The version string e.g. '0.1.2'.
Changed in version 0.1.9: Becomes string. (It was tuple before.)
(tuple) The version tuple e.g. (0, 1, 2).
Changed in version 0.1.9: Becomes tuple. (It was string before.)
(basestring) The version string of the linked ImageMagick library. The exactly same string to the result of GetMagickVersion() function.
Example:
'ImageMagick 6.7.7-6 2012-06-03 Q16 http://www.imagemagick.org'
New in version 0.2.1.
(tuple) The version tuple e.g. (6, 7, 7, 6) of MAGICK_VERSION.
New in version 0.2.1.
(numbers.Integral) The version number of the linked ImageMagick library.
New in version 0.2.1.
(basestring) The date string e.g. '2012-06-03' of MAGICK_RELEASE_DATE_STRING. This value is the exactly same string to the result of GetMagickReleaseDate() function.
New in version 0.2.1.
(datetime.date) The release date of the linked ImageMagick library. The same to the result of GetMagickReleaseDate() function.
New in version 0.2.1.
(numbers.Integral) The quantum depth configuration of the linked ImageMagick library. One of 8, 16, 32, or 64.
New in version 0.3.0.
Wand has the list for users. If you want to subscribe the list, just send a mail to:
The list archive provided by Librelist is synchronized every hour.
There’s a Stack Overflow tag for Wand:
http://stackoverflow.com/questions/tagged/wand
Freely ask questions about Wand including troubleshooting. Thanks for sindikat‘s contribution.
There’s a Quora topic for Wand: Wand (ImageMagick binding). Be free to add questions to the topic, though it’s suitable for higher-level questions rather than troubleshooting.
Wand is an open source software written by Hong Minhee (initially written for StyleShare). See also the complete list of contributors as well. The source code is distributed under MIT license and you can find it at GitHub repository. Check out now:
$ git clone git://github.com/dahlia/wand.git
If you find a bug, please notify to our issue tracker. Pull requests are always welcome!
We discuss about Wand’s development on IRC. Come #wand channel on freenode network.
Check out Wand Changelog also.