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§

ImageMetadata
An image’s dimensions, along with any comments found in the data.

Enums§

DecodingError
An error that occurred while decoding an image.
Error
An error that occurred while reading an image.
JpegDecodingError
An error that occurred while decoding a JPEG image.
PngDecodingError
An error that occurred while decoding a PNG image.

Functions§

read_bytes
Reads the dimensions and comments of an image from a byte slice.
read_file
Reads the dimensions and comments of an image from a file.