Skip to content

emf

emf

Image header parser for EMF (Enhanced Metafile) images.

An EMF file opens with an EMR_HEADER record whose ENHMETAHEADER structure carries both the physical extent of the picture and the resolution of the device it was recorded against. Both are needed: the extent alone says how large the picture is, and the device resolution is what turns that into a pixel count that agrees with what Word shows.

Emf

Emf(
    px_width: int,
    px_height: int,
    horz_dpi: int,
    vert_dpi: int,
    orientation: int = 1,
)

Bases: BaseImageHeader

Image header parser for EMF images.

Source code in src/docx/image/image.py
def __init__(
    self,
    px_width: int,
    px_height: int,
    horz_dpi: int,
    vert_dpi: int,
    orientation: int = 1,
):
    self._px_width = px_width
    self._px_height = px_height
    self._horz_dpi = horz_dpi
    self._vert_dpi = vert_dpi
    self._orientation = orientation

content_type property

content_type

MIME content type for this image, unconditionally image/x-emf for EMF images.

default_ext property

default_ext

Default filename extension, always 'emf' for EMF images.

from_stream classmethod

from_stream(stream)

Return an Emf instance with header properties parsed from stream.

Source code in src/docx/image/emf.py
@classmethod
def from_stream(cls, stream):
    """Return an |Emf| instance with header properties parsed from `stream`."""
    header = cls._read_header(stream)
    horz_dpi, vert_dpi = cls._dpi_from_header(header)
    inch_width, inch_height = cls._extents_in_inches(header)
    px_width = int(round(inch_width * horz_dpi))
    px_height = int(round(inch_height * vert_dpi))
    return cls(px_width, px_height, horz_dpi, vert_dpi)