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 filter types.
See also
An image object.
| Parameters: |
|
|---|
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 |
(wand.color.Color) The image background color. It can also be set to change the background color.
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 |
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.
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: |
|
|---|
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 |
Crops the image in-place.
+--------------------------------------------------+
| ^ ^ |
| | | |
| top | |
| | | |
| v | |
| <-- left --> +-------------------+ bottom |
| | ^ | | |
| | <-- width --|---> | | |
| | height | | |
| | | | | |
| | v | | |
| +-------------------+ v |
| <--------------- right ----------> |
+--------------------------------------------------+
| Parameters: |
|
|---|
Note
If you want to crop the image but not in-place, use slicing operator.
(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
(numbers.Integral) The height of this image.
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 |
(basestring) The MIME type of the image e.g. 'image/jpeg', 'image/png'.
(int) The maxumim value of a color channel that is supported by the imagemgick library.
Reset the coordinate frame of the image so to the upper-left corner is (0, 0) again (crop and rotate operations change it).
Resizes the image.
| Parameters: |
|
|---|
Rotates the image. It takes a background color for degree that isn’t a multiple of 90.
| Parameters: |
|
|---|
Saves the image into the file or filename. It takes only one argument at a time.
| Parameters: |
|
|---|
(str) The SHA-256 message digest for the image pixel stream.
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 |
|---|
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: |
|
|---|
(numbers.Integral) The width of this image.
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 |
|---|
Clones the same iterator.
An error that rises when some code tries access to an already closed image.