Skip to main content

decode_image_bounded

Function decode_image_bounded 

Source
pub fn decode_image_bounded(bytes: &[u8]) -> Result<DynamicImage, String>
Expand description

Decode an image with allocation limits. A tiny file declaring 60000×60000 would otherwise allocate ~14 GB before a single pixel decodes — every decode of bytes we didn’t author must go through this.

Applies EXIF orientation to the pixels. Camera photos store their pixels in the sensor’s native axis plus an orientation tag; <img> honours that tag, but our re-encode strips all metadata, so an un-baked decode would ship the sensor pixels with no tag and the receiver sees the photo rotated. Baking it in here keeps every downstream path (compress, thumbhash, dimensions) upright.