

Image moduleImageChops (“channel operations”) moduleImageCms moduleImageColor moduleImageDraw moduleImageEnhance moduleImageFile moduleImageFilter moduleImageFont moduleImageGrab moduleImageMath moduleImageMorph moduleImageOps moduleImagePalette moduleImagePath moduleImageQt moduleImageSequence moduleImageShow moduleImageStat moduleImageText moduleImageTk moduleImageTransform moduleImageWin module (Windows-only)ExifTags moduleTiffTags moduleJpegPresets modulePSDraw modulePixelAccess classfeatures moduleImageFile module¶TheImageFile module provides support functions for the image openand save functions.
In addition, it provides aParser class which can be used to decodean image piece by piece (e.g. while receiving it over a network connection).This class implements the same consumer interface as the standardsgmllibandxmllib modules.
fromPILimportImageFilefp=open("hopper.ppm","rb")p=ImageFile.Parser()while1:s=fp.read(1024)ifnots:breakp.feed(s)im=p.close()im.save("copy.jpg")
Bases:NamedTuple
_Tile(codec_name, extents, offset, args)
Incremental image parser. This class implements the standardfeed/close consumer interface.
(Consumer) Close the stream.
An image object.
OSError – If the parser failed to parse the image file eitherbecause it cannot be identified or cannot bedecoded.
Override to perform codec specific initialization
args – Tuple of arg items from the tile entry
None
Bases:PyCodec
Python implementation of a format decoder. Override this class andadd the decoding logic in thedecode() method.
SeeWriting Your Own File Codec in Python
Override to perform the decoding process.
buffer – A bytes object with the data to be decoded.
A tuple of(bytesconsumed,errcode).If finished with decoding return -1 for the bytes consumed.Err codes are fromImageFile.ERRORS.
Convenience method to set the internal image from a stream of raw data
data – Bytes to be set
rawmode – The rawmode to be used for the decoder.If not specified, it will default to the mode of the image
extra – Extra arguments for the decoder.
None
Bases:PyCodec
Python implementation of a format encoder. Override this class andadd the decoding logic in theencode() method.
SeeWriting Your Own File Codec in Python
Override to perform the encoding process.
bufsize – Buffer size.
A tuple of(bytesencoded,errcode,bytes).If finished with encoding return 1 for the error code.Err codes are fromImageFile.ERRORS.
Bases:Image
Base class for image file format handlers.
Closes the file pointer, if possible.
This operation will destroy the image core and release its memory.The image data will be unusable afterward.
This function is required to close images that have multiple frames orhave not had their file read and closed by theload() method. SeeFile handling in Pillow formore information.
Load image data based on tile list
Whether or not to load truncated image files. User code may change this.
By default, Pillow processes image data in blocks. This helps to prevent excessive useof resources. Codecs may disable this behaviour with_pulls_fd or_pushes_fd.
When reading an image, this is the number of bytes to read at once.
When writing an image, this is the number of bytes to write at once.If the image width times 4 is greater, then that will be used instead.Plugins may also set a greater number.
User code may set this to another number.
Dict of known error codes returned fromPyDecoder.decode(),PyEncoder.encode()PyEncoder.encode_to_pyfd() andPyEncoder.encode_to_file().