“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 |
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'
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 |
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 |
Copies the given band to the alpha layer of the given image.
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.
Parameters: |
|
---|
Saves an image with a filename and raise the specific InvalidWriteFormatError in case of an error instead of a KeyError.
Parameters: |
|
---|
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 |