Skip to main content

peek_info

Function peek_info 

Source
pub fn peek_info(data: &[u8]) -> Result<ImageInfo>
Expand description

Parse image headers and return the native dimensions, format, and EXIF orientation without decoding pixels.

Recommended for one-shot flows that allocate a tensor sized to the image:

use edgefirst_codec::{peek_info, ImageDecoder, ImageLoad};
use edgefirst_tensor::{Tensor, TensorMemory};

let data = std::fs::read("image.jpg").unwrap();
let info = peek_info(&data).unwrap();
let mut tensor = Tensor::<u8>::image(info.width, info.height, info.format,
                                      Some(TensorMemory::Mem)).unwrap();
let mut decoder = ImageDecoder::new();
tensor.load_image(&mut decoder, &data).unwrap();