This crate provides native rust implementations of image encoding and decoding as well as some basic image manipulation functions. Additional documentation can currently also be found in the README.md file which is most easily viewed on github.
There are two core problems for which this library provides solutions: a unified interface for image encodings and simple generic buffers for their content. It’s possible to use either feature without the other. The focus is on a small and stable set of common operations that can be supplemented by other specialized crates. The library also prefers safe solutions with few dependencies.
Load images using
use std::io::Cursor; use image::io::Reader as ImageReader; let img = ImageReader::open("myimage.png")?.decode()?; let img2 = ImageReader::new(Cursor::new(bytes)).with_guessed_format()?.decode()?;
img.save("empty.jpg")?; let mut bytes: Vec<u8> = Vec::new(); img2.write_to(&mut Cursor::new(&mut bytes), image::ImageOutputFormat::Png)?;
With default features, the crate includes support for many common image formats.
The two main types for storing images:
ImageBufferwhich holds statically typed image contents.
DynamicImagewhich is an enum over the supported ImageBuffer formats and supports conversions between them.
As well as a few more specialized options:
GenericImagetrait for a mutable image buffer.
GenericImageViewtrait for read only references to a GenericImage.
flatmodule containing types for interoperability with generic channel matrices and foreign interfaces.
ImageDecoderRect traits are implemented for many image file
formats. They decode image data by directly on raw byte slices. Given an ImageDecoder, you can
produce a DynamicImage via
ImageEncoder provides the analogous functionality for encoding image data.
pub use crate::error::ImageError;
pub use crate::error::ImageResult;
pub use crate::flat::FlatSamples;
ColorType. Not all possible pixels represent one of the predefined