Image Objects
Objects for handling images in PowerPoint presentations.Image
Immutable value object representing an image such as a JPEG, PNG, or GIF.Class Methods
Create a new Image object from binary image data.Parameters:
blob(bytes): Binary image datafilename(str | None): Optional filename for the image
Create a new Image object from a file.Parameters:
image_file(str | file-like): Path to image file (string) or a file-like object
Properties
The binary image bytestream of this image.
MIME-type of this image, e.g.
"image/jpeg" or "image/png".A (horz_dpi, vert_dpi) 2-tuple specifying the dots-per-inch resolution.Returns
(72, 72) if DPI is not specified in the image file or if an invalid value is present.Canonical file extension for this image, e.g.
'png' or 'jpg'.The extension is always lowercase and represents the canonical extension for the image format, regardless of the original filename extension.Supported formats:'bmp'- Windows Bitmap'gif'- Graphics Interchange Format'jpg'- JPEG'png'- Portable Network Graphics'tiff'- Tagged Image File Format'wmf'- Windows Metafile
Filename from the path used to load this image.Returns
None if the image was loaded from an in-memory stream rather than a file.40-character SHA1 hash digest of the image blob.Example:
"1be010ea47803b00e140b852765cdf84f491da47"A (width, height) 2-tuple specifying the dimensions of this image in pixels.
ImagePart
An image part within a presentation package.Class Methods
Create a new ImagePart instance containing the specified image.Parameters:
package(Package): The presentation packageimage(Image): An Image object
Properties
The filename associated with this image.Either the original filename or a generic name like
'image.jpg'. Images created from a file path retain that filename; those from file-like objects get a generic name.File-name extension for this image, e.g.
'png' or 'jpg'.An Image object containing the image in this image part.
This is a
pptx.parts.image.Image object, not a PIL Image.The 40-character SHA1 hash digest for the image binary.Example:
"1be010ea47803b00e140b852765cdf84f491da47"Methods
Calculate scaled image dimensions in EMU.Parameters:
scaled_cx(int | None): Desired width in EMU, or Nonescaled_cy(int | None): Desired height in EMU, or None
- If both are
None: Returns native image size - If both are specified: Returns values unchanged
- If only one is specified: Calculates the other to preserve aspect ratio