“If the image has a transparent mask, a RGB checkerboard will be drawn in the background.
Note
In case of a thumbnail, the resulting image can not be used for the cache, as it replaces the transparency layer with a non transparent checkboard.
Parameter: | image (pil.Image) – image |
---|---|
Returns: | image, with checkboard if transparant |
Return type: | pil.Image |
Blend two images with each other. If the images differ in size the color will be used for undefined pixels.
Parameters: |
|
---|---|
Returns: | blended image |
Return type: | pil.Image |
Calculate location based on offset and justification. Offsets can be positive and negative.
Parameters: |
|
---|---|
Returns: | location |
Return type: | tuple of int |
>>> calculate_location(50, 50, 'Left', 'Middle', (100,100), (10,10))
(50, 45)
Draw an n x n checkboard, which is often used as background for transparent images. The checkboards are stored in the CHECKBOARD cache.
Parameters: |
|
---|---|
Returns: | checkboard image |
Return type: | pil.Image |
Returns a converted copy of an image
Parameters: |
|
---|---|
Returns: | the converted image |
Return type: | PIL image object |
Converts image into a processing-safe mode.
Parameter: | image (PIL image object) – input image |
---|---|
Returns: | the converted image |
Return type: | PIL image object |
Converts image into a saving-safe mode.
Parameters: |
|
---|---|
Returns: | the converted image |
Return type: | PIL image object |
Fills given image with background color.
Parameters: |
|
---|---|
Returns: | filled image |
Return type: | pil.Image |
Fit a color into a palette. If the color exists already in the palette return its current index, otherwise add the color to the palette if possible. Returns -1 for color index if all colors are used already.
Parameters: |
|
---|---|
Returns: | color index, (new) palette |
Return type: | (r, g, b) tuple, sequence of (r, g, b) tuples |
Flatten a list.
Parameter: | l (list) – list to be flattened |
---|---|
Returns: | flattened list |
Return type: | list |
>>> flatten([[1, 2], [3]])
[1, 2, 3]
Generate new layer for backgrounds or watermarks on which a given image mark can be positioned, scaled or repeated.
Parameters: |
|
---|---|
Returns: | generated layer |
Return type: | pil.Image |
Gets the image alpha band. Can handles P mode images with transpareny. Returns a band with all values set to 255 if no alpha band exists.
Parameter: | image (PIL image object) – input image |
---|---|
Returns: | alpha as a band |
Return type: | single band image object |
Gets the exif orientation of an image.
Parameter: | image (pil.Image) – image |
---|---|
Returns: | orientation |
Return type: | int |
Get the transposition methods necessary to aling the image to its exif orientation.
Parameter: | orientation (int) – exif orientation |
---|---|
Returns: | (transposition methods, reverse transpostion methods) |
Return type: | tuple |
Guess the image format by the file extension.
Parameter: | ext (string) – file extension |
---|---|
Returns: | image format |
Return type: | string |
Warning
This is only meant to check before saving files. For existing files open the image with PIL and check its format attribute.
>>> get_format('jpg')
'JPEG'
Convert the image in the file bytes of the image. By consequence this byte data is different for the chosen format (JPEG, TIFF, ...).
Parameters: |
|
---|---|
Returns: | byte data of the image |
Guess the image format by the filename.
Parameter: | filename (string) – filename |
---|---|
Returns: | image format |
Return type: | string |
Warning
This is only meant to check before saving files. For existing files open the image with PIL and check its format attribute.
>>> get_format_filename('test.tif')
'TIFF'
Gets the palette of an image as a sequence of (r, g, b) tuples.
Parameter: | image – image with a palette |
---|---|
Returns: | palette colors |
Return type: | a sequence of (r, g, b) tuples |
Figure out recursively the quality save parameter to obtain a certain image size. This mostly used for JPEG images.
Parameters: |
|
---|---|
Returns: | save quality |
Return type: | int |
Example:
filename = '/home/stani/sync/Desktop/IMGA3345.JPG'
im = Image.open(filename)
q = get_quality(im, 300000, "JPEG")
im.save(filename.replace('.jpg', '_sized.jpg'))
Get the reverse transposition method.
Parameter: | transposition – transpostion, e.g. Image.ROTATE_90 |
---|---|
Returns: | inverse transpostion, e.g. Image.ROTATE_270 |
Gets the size in bytes if the image would be written to a file.
Parameter: | format (string) – image file format (e.g. 'JPEG') |
---|---|
Returns: | the file size in bytes |
Return type: | int |
Get unused color indices in an image palette.
Parameter: | image – image with a palette |
---|---|
Returns: | unused color indices of the palette |
Return type: | set of 0-255 |
Get used colors in an image palette as a sequence of (r, g, b) tuples.
Parameter: | image – image with a palette |
---|---|
Returns: | used colors of the palette |
Return type: | sequence of (r, g, b) tuples |
Get used color indices in an image palette.
Parameter: | image – image with a palette |
---|---|
Returns: | used colors of the palette |
Return type: | set of integers (0-255) |
Checks if the image has an alpha band. i.e. the image mode is either RGBA or LA. The transparency in the P mode doesn’t count as an alpha band
Parameter: | image (PIL image object) – the image to check |
---|---|
Returns: | True or False |
Return type: | boolean |
Checks if the image has transparency. The image has an alpha band or a P mode with transparency.
Parameter: | image (PIL image object) – the image to check |
---|---|
Returns: | True or False |
Return type: | boolean |
Get a color with same color component values.
>>> im = Image.new('RGB', (1,1))
>>> identity_color(im, 2)
(2, 2, 2)
>>> im = Image.new('L', (1,1))
>>> identity_color(im, 7)
7
Open local files or remote files over http.
Parameter: | uri (string) – image location |
---|---|
Returns: | image |
Return type: | pil.Image |
Open image from format data.
Parameter: | data (string) – image format data |
---|---|
Returns: | image |
Return type: | pil.Image |
Open local files or remote files over http and transpose the image to its exif orientation.
Parameter: | uri (string) – image location |
---|---|
Returns: | image |
Return type: | pil.Image |
“Pastes the source image into the destination image while using an alpha channel if available.
Parameters: |
|
---|
Copies the given band to the alpha layer of the given image.
Parameters: |
|
---|
Copies the palette and transparency of one image to another.
Parameters: |
|
---|
Returns an image with reduced opacity if opacity is within [0, 1].
Parameters: |
|
---|---|
Returns im: | image |
Return type: | pil.Image |
>>> im = Image.new('RGBA', (1, 1), (255, 255, 255))
>>> im = reduce_opacity(im, 0.5)
>>> im.getpixel((0,0))
(255, 255, 255, 127)
Returns a copy of the image after removing the alpha band or transparency
Parameter: | image (PIL image object) – input image |
---|---|
Returns: | the input image after removing the alpha band or transparency |
Return type: | PIL image object |
Saves an image with a filename and raise the specific InvalidWriteFormatError in case of an error instead of a KeyError. Also can hack around UnicodeEncodeError (eg for IM format)
Parameters: |
|
---|
Saves an image with a filename and raise the specific InvalidWriteFormatError in case of an error instead of a KeyError. It can also save IM files with unicode.
Parameters: |
|
---|
Work around for bug in Pil 1.1.7
Parameter: | image (PIL image object) – input image |
---|---|
Returns: | the different color bands of the image (eg R, G, B) |
Return type: | tuple |
Transpose with a sequence of transformations, mainly useful for exif.
Parameters: |
|
---|---|
Returns: | transposed image |
Return type: | pil.Image |
Transpose an image to its exif orientation.
Parameters: |
|
---|---|
Returns: | transposed image |
Return type: | pil.Image |