Paper Office
paper-pptxAPI referenceparts.image

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

attributeblobbytes

Contents 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_typestr

Content-type (MIME-type) of this part.

desc

attributedescstr

The 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

attributeextstr

File-name extension for this image e.g. 'png'.

image

attributeimageImage

An Image object containing the image in this image part.

Note this is a pptx.image.Image object, not a PIL Image.

package

attributepackagePackage

Package this part belongs to.

partname

attributepartnamePackURI

PackURI partname for this part, e.g. "/ppt/slides/slide1.xml".

rels

attributerels_Relationships

Collection of relationships from this part to other parts.

sha1

attributesha1str

The 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) -> Self

Return cls instance loaded from arguments.

This one is a straight pass-through, but subtypes may do some pre-processing, see XmlPart for an example.

parampartnamePackURI
paramcontent_typestr
parampackagePackage
paramblobbytes

Returns

typing_extensions.Self

load_rels_from_xml

funcload_rels_from_xml(xml_rels: CT_Relationships, parts: dict[PackURI, Part]) -> None

load _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_Relationships
parampartsdict[PackURI, Part]

Returns

None

new

funcnew(package: Package, image: Image) -> ImagePart

Return new ImagePart instance containing image.

image is an Image object.

parampackagePackage
paramimageImage

Returns

pptx.parts.image.ImagePart
funcpart_related_by(reltype: str) -> Part

Return (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.

paramreltypestr

Returns

pptx.opc.package.Part

relate_to

funcrelate_to(target: Part | str, reltype: str, is_external: bool = False) -> str

Return 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 | str
paramreltypestr
paramis_externalbool
= False

Returns

str
funcrelated_part(rId: str) -> Part

Return related Part subtype identified by rId.

paramrIdstr

Returns

pptx.opc.package.Part

scale

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 | None
paramscaled_cyint | None

Returns

tuple[int, int]

target_ref

functarget_ref(rId: str) -> str

Return URL contained in target ref of relationship identified by rId.

paramrIdstr

Returns

str

On this page