media_type_of
Finds the media type of an image from its first bytes (its magic number), whatever its name
says: PNG, JPEG, GIF, WebP, AVIF and SVG. SVG has no magic number, so it is recognized as
text whose first element is <svg, possibly after a byte order mark, whitespace, an XML
declaration, comments or a doctype.
Import
Section titled “Import”Cargo feature bytes (enabled by default). To compile only this module:
or in Cargo.toml:
Signature
Section titled “Signature”Parameters
Section titled “Parameters”| Parameter | Type | Description |
|---|---|---|
bytes | &[u8] | The start of the file: 512 bytes are enough for every type but a long SVG prolog. |
Returns
Section titled “Returns”Option<&'static str> — The media type ("image/png", …), or None when it is none of these.
