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 Image.compression types.
New in version 0.3.6.
(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.
Equalizes the image histogram
New in version 0.3.10.
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.
Changes the value of individual pixels based on the intensity of each pixel compared to threshold. The result is a high-contrast, two color image. It manipulates the image in place.
Parameters: |
|
---|
New in version 0.3.10.
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.