Presently, using image::load_from_memory will make an attempt to guess the image's format using magic numbers at the beginning of the image's bytes. WebP's magic bytes are defined here:
static MAGIC_BYTES: [(&'static [u8], ImageFormat); 11] = [
//omitted other definitions
(b"WEBP", ImageFormat::WEBP),
//omitted other definitions
];
This would cause any byte sequence starting with the bytes for "WEBP" to be recognized as WebP images; however, WebP images do not actually begin with the ASCII bytes "WEBP", but instead, their file header looks like this:
0 1 2 3
0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 'R' | 'I' | 'F' | 'F' |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| File Size |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| 'W' | 'E' | 'B' | 'P' |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
(taken from the WebP Container Specification)
Because of this, WEBP images' bytes are not properly recognized by load_from_memory.
Presently, using
image::load_from_memorywill make an attempt to guess the image's format using magic numbers at the beginning of the image's bytes. WebP's magic bytes are defined here:This would cause any byte sequence starting with the bytes for "WEBP" to be recognized as WebP images; however, WebP images do not actually begin with the ASCII bytes "WEBP", but instead, their file header looks like this:
(taken from the WebP Container Specification)
Because of this, WEBP images' bytes are not properly recognized by
load_from_memory.