Skip to content

bmp

bmp

Bmp

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

Bases: BaseImageHeader

Image header parser for BMP 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/bmp for BMP images.

default_ext property

default_ext

Default filename extension, always 'bmp' for BMP images.

from_stream classmethod

from_stream(stream)

Return Bmp instance having header properties parsed from the BMP image in stream.

Source code in src/docx/image/bmp.py
@classmethod
def from_stream(cls, stream):
    """Return |Bmp| instance having header properties parsed from the BMP image in
    `stream`."""
    stream_rdr = StreamReader(stream, LITTLE_ENDIAN)

    px_width = stream_rdr.read_long(0x12)
    px_height = stream_rdr.read_long(0x16)

    horz_px_per_meter = stream_rdr.read_long(0x26)
    vert_px_per_meter = stream_rdr.read_long(0x2A)

    horz_dpi = cls._dpi(horz_px_per_meter)
    vert_dpi = cls._dpi(vert_px_per_meter)

    return cls(px_width, px_height, horz_dpi, vert_dpi)