Crate pb_imgsize
source ·Expand description
Fast reader for JPEG and PNG comments and dimensions.
The pb-imgsize
crate provides a reader for JPEG and PNG images that can
quickly extract the image’s dimensions and any comments embedded in the
image.
For PNG images, the dimensions are extracted from the IHDR chunk, and the comments are extracted from tEXt chunks with the keyword “comment”.
For JPEG images, the dimensions are extracted from the SOFx chunk, and the comments are extracted from COM chunks.
The reader is fast because it only reads the chunks that are necessary to extract the dimensions and comments. It does not decode the image data.
The reader does not attempt to read EXIF data.
Example
let data = include_bytes!("buttercups.jpg");
let metadata = pb_imgsize::read_bytes(data).unwrap();
assert_eq!(512, metadata.width);
assert_eq!(341, metadata.height);
assert_eq!(vec![b"Buttercups".to_vec()], metadata.comments);
Structs
- An image’s dimensions, along with any comments found in the data.
Enums
- An error that occurred while decoding an image.
- An error that occurred while reading an image.
- An error that occurred while decoding a JPEG image.
- An error that occurred while decoding a PNG image.
Functions
- Reads the dimensions and comments of an image from a byte slice.
- Reads the dimensions and comments of an image from a file.