ImagePart
paper-pptx 0.2.0 API reference
An image part.
An image part generally has a partname matching the regex ppt/media/image[1-9][0-9]*.*.
ImagePart(partname: PackURI, content_type: str, package: Package, blob: bytes, filename: str | None = None)Attributes
blob
attributeblobbytesContents of this package part as a sequence of bytes.
Intended to be overridden by subclasses. Default behavior is to return the blob initial
loaded during Package.open() operation.
content_type
attributecontent_typestrContent-type (MIME-type) of this part.
desc
attributedescstrThe filename associated with this image.
Either the filename of the original image or a generic name of the form image.ext where
ext is appropriate to the image file format, e.g. 'jpg'. An image created using a path
will have that filename; one created with a file-like object will have a generic name.
ext
attributeextstrFile-name extension for this image e.g. 'png'.
image
attributeimageImageAn Image object containing the image in this image part.
Note this is a pptx.image.Image object, not a PIL Image.
package
attributepackagePackagePackage this part belongs to.
partname
attributepartnamePackURIPackURI partname for this part, e.g. "/ppt/slides/slide1.xml".
rels
attributerels_RelationshipsCollection of relationships from this part to other parts.
sha1
attributesha1strThe 40-character SHA1 hash digest for the image binary of this image part.
like: "1be010ea47803b00e140b852765cdf84f491da47".
Functions
load
funcload(partname: PackURI, content_type: str, package: Package, blob: bytes) -> SelfReturn cls instance loaded from arguments.
This one is a straight pass-through, but subtypes may do some pre-processing, see XmlPart for an example.
parampartnamePackURIparamcontent_typestrparampackagePackageparamblobbytesReturns
typing_extensions.Selfload_rels_from_xml
funcload_rels_from_xml(xml_rels: CT_Relationships, parts: dict[PackURI, Part]) -> Noneload _Relationships for this part from xml_rels.
Part references are resolved using the parts dict that maps each partname to the loaded
part with that partname. These relationships are loaded from a serialized package and so
already have assigned rIds. This method is only used during package loading.
paramxml_relsCT_Relationshipsparampartsdict[PackURI, Part]Returns
Nonenew
funcnew(package: Package, image: Image) -> ImagePartReturn new ImagePart instance containing image.
image is an Image object.
parampackagePackageparamimageImageReturns
pptx.parts.image.ImagePartpart_related_by
funcpart_related_by(reltype: str) -> PartReturn (single) part having relationship to this package of reltype.
Raises KeyError if no such relationship is found and ValueError if more than one such
relationship is found.
paramreltypestrReturns
pptx.opc.package.Partrelate_to
funcrelate_to(target: Part | str, reltype: str, is_external: bool = False) -> strReturn rId key of relationship of reltype to target.
If such a relationship already exists, its rId is returned. Otherwise the relationship is added and its new rId returned.
paramtargetPart | strparamreltypestrparamis_externalbool= FalseReturns
strrelated_part
funcrelated_part(rId: str) -> PartReturn related Part subtype identified by rId.
paramrIdstrReturns
pptx.opc.package.Partscale
funcscale(scaled_cx: int | None, scaled_cy: int | None) -> tuple[int, int]Return scaled image dimensions in EMU based on the combination of parameters supplied.
If scaled_cx and scaled_cy are both None, the native image size is returned. If
neither scaled_cx nor scaled_cy is None, their values are returned unchanged. If a
value is provided for either scaled_cx or scaled_cy and the other is None, the
missing value is calculated such that the image's aspect ratio is preserved.
paramscaled_cxint | Noneparamscaled_cyint | NoneReturns
tuple[int, int]target_ref
functarget_ref(rId: str) -> strReturn URL contained in target ref of relationship identified by rId.
paramrIdstrReturns
str