Expand description
§Overview
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.
§High level API
Load images using ImageReader
:
use std::io::Cursor;
use image::ImageReader;
let img = ImageReader::open("myimage.png")?.decode()?;
let img2 = ImageReader::new(Cursor::new(bytes)).with_guessed_format()?.decode()?;
And save them using save
or write_to
methods:
img.save("empty.jpg")?;
let mut bytes: Vec<u8> = Vec::new();
img2.write_to(&mut Cursor::new(&mut bytes), image::ImageFormat::Png)?;
With default features, the crate includes support for many common image formats.
§Image buffers
The two main types for storing images:
ImageBuffer
which holds statically typed image contents.DynamicImage
which is an enum over the supportedImageBuffer
formats and supports conversions between them.
As well as a few more specialized options:
GenericImage
trait for a mutable image buffer.GenericImageView
trait for read only references to aGenericImage
.flat
module containing types for interoperability with generic channel matrices and foreign interfaces.
§Low level encoding/decoding API
Implementations of ImageEncoder
provides low level control over encoding:
let encoder = JpegEncoder::new_with_quality(&mut writer, 95);
img.write_with_encoder(encoder)?;
While ImageDecoder
and ImageDecoderRect
give access to more advanced decoding options:
let decoder = PngDecoder::new(&mut reader)?;
let icc = decoder.icc_profile();
let img = DynamicImage::from_decoder(decoder)?;
Modules§
- Iterators and other auxiliary structure for the
ImageBuffer
type. - Encoding and decoding for various image file formats.
- Contains detailed error representation.
- Image representations for ffi.
- Image Processing Functions
- deprecated io module the original io module has been renamed to
image_reader
- Mathematical helper functions and types.
- Types describing image metadata
Structs§
- The delay of a frame relative to the previous one.
- A flat buffer over a (multi channel) image.
- A single animation frame
- An implementation dependent iterator, reading the frames as requested
- Generic image buffer
- A multi-format image reader.
- Set of supported strict limits for a decoder.
- Resource limits for decoding.
- Grayscale colors.
- Grayscale colors + alpha channel
- Immutable pixel iterator
- RGB colors.
- RGB colors + alpha channel
- A View into another image
Enums§
- An enumeration over supported color types and bit depths
- A Dynamic Image
- An enumeration of color types encountered in image formats.
- The generic error type for image operations.
- An enumeration of supported image formats. Not all formats support both encoding and decoding.
Traits§
AnimationDecoder
trait- Types which are safe to treat as an immutable byte slice in a pixel layout for image encoding.
- A trait for manipulating images.
- Trait to inspect an image.
- The trait that all decoders implement
- Specialized image decoding not be supported by all formats
- The trait all encoders implement
- A generalized pixel.
- The pixel with an associated
ColorType
. Not all possible pixels represent one of the predefinedColorType
s. - The type of each channel in a pixel. For example, this can be
u8
,u16
,f32
.
Functions§
- Guess image format from memory block
- Read a tuple containing the (width, height) of the image located at the specified path. This is faster than fully loading the image and then getting its dimensions.
- Create a new image from a Reader.
- Create a new image from a byte slice
- Create a new image from a byte slice
- Open the image located at the path specified. The image’s format is determined from the path’s file extension.
- Saves the supplied buffer to a file at the path specified.
- Saves the supplied buffer to a file at the path specified in the specified format.
- Writes the supplied buffer to a writer in the specified format.
Type Aliases§
- Sendable grayscale + alpha channel image buffer
- Sendable grayscale image buffer
- Result of an image decoding/encoding process
- An image buffer for 32-bit float RGB pixels, where the backing container is a flattened vector of floats.
- Sendable Rgb image buffer
- An image buffer for 32-bit float RGBA pixels, where the backing container is a flattened vector of floats.
- Sendable Rgb + alpha channel image buffer