svg
svg
¶
Image header parser for SVG images.
SVG is XML, so there is no fixed-offset magic number to match and no binary header to
unpack. Size comes from the width and height attributes of the root <svg> element,
which are CSS lengths and may carry any of the usual units, or — when those are absent
or given as percentages, which is common for icons meant to scale — from the viewBox.
One SVG user unit is one CSS pixel, 1/96 inch, which is why the resolution reported here is 96 rather than the 72 the resolution-free raster formats assume.
Svg
¶
Bases: BaseImageHeader
Image header parser for SVG images.
Source code in src/docx/image/image.py
content_type
property
¶
MIME content type for this image, unconditionally image/svg+xml for SVG
images.
sniff
classmethod
¶
True when header looks like the start of an SVG document.
SVG has no magic number, so detection is by finding an <svg root element ahead
of any other element. Matched against the leading bytes of the file rather than
at a fixed offset, because an XML declaration, a DOCTYPE and comments may all
precede the root.
Source code in src/docx/image/svg.py
from_stream
classmethod
¶
Return an Svg instance with header properties parsed from stream.