Image
paper-docx 0.2.0 API reference
Graphical image stream such as JPEG, PNG, or GIF with properties and methods required by ImagePart.
Image(blob: bytes, filename: str, image_header: BaseImageHeader)Attributes
blob
attributeblobThe bytes of the image 'file'.
content_type
attributecontent_typestrMIME content type for this image, e.g. 'image/jpeg' for a JPEG image.
ext
attributeextThe file extension for the image.
If an actual one is available from a load filename it is used. Otherwise a canonical extension is assigned based on the content type. Does not contain the leading period, e.g. 'jpg', not '.jpg'.
filename
attributefilenameOriginal image file name, if loaded from disk, or a generic filename if loaded from an anonymous stream.
height
attributeheightInchesA Length value representing the native height of the image, calculated from
the values of px_height and vert_dpi.
horz_dpi
attributehorz_dpiintInteger dots per inch for the width of this image.
Defaults to 72 when not present in the file, as is often the case.
px_height
attributepx_heightintThe vertical pixel dimension of the image.
px_width
attributepx_widthintThe horizontal pixel dimension of the image.
sha1
attributesha1SHA1 hash digest of the image blob.
vert_dpi
attributevert_dpiintInteger dots per inch for the height of this image.
Defaults to 72 when not present in the file, as is often the case.
width
attributewidthInchesA Length value representing the native width of the image, calculated from
the values of px_width and horz_dpi.
Functions
from_blob
funcfrom_blob(blob: bytes) -> ImageReturn a new Image subclass instance parsed from the image binary contained
in blob.
paramblobbytesReturns
docx.image.image.Imagefrom_file
funcfrom_file(image_descriptor: str | IO[bytes])Return a new Image subclass instance loaded from the image file identified
by image_descriptor, a path or file-like object.
paramimage_descriptorstr | IO[bytes]scaled_dimensions
funcscaled_dimensions(width: int | Length | None = None, height: int | Length | None = None) -> Tuple[Length, Length](cx, cy) pair representing scaled dimensions of this image.
The native dimensions of the image are scaled by applying the following rules to
the width and height arguments.
- If both
widthandheightare specified, the return value is (width,height); no scaling is performed. - If only one is specified, it is used to compute a scaling factor that is then applied to the unspecified dimension, preserving the aspect ratio of the image.
- If both
widthandheightareNone, the native dimensions are returned.
The native dimensions are calculated using the dots-per-inch (dpi) value
embedded in the image, defaulting to 72 dpi if no value is specified, as is
often the case. The returned values are both Length objects.
paramwidthint | Length | None= Noneparamheightint | Length | None= NoneReturns
typing.Tuple[docx.shared.Length, docx.shared.Length]