+2
日增长
5,912
stars
746
forks
77
watchers
1,817
prs
1,249
issues
0
releases
README
Image
Maintainers: @197g, @fintelia
How to contribute
An Image Processing Library
This crate provides basic image processing functions and methods for converting to and from various image formats.
All image processing functions provided operate on types that implement the GenericImageView and GenericImage traits and return an ImageBuffer.
High level API
Load images using [ImageReader]:
rust,ignore
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:
rust,ignore
img.save("empty.jpg")?;
let mut bytes: Vec = Vec::new();
img2.write_to(&mut Cursor::new(&mut bytes), image::ImageFormat::Png)?;
Supported Image Formats
With default features enabled, image provides implementations of many common
image format encoders and decoders.
Decoding support for additional image formats is provided by
image-extras, and the same plugin
interface lets third-party crates act as format implementations for image. If
you need to handle some other image format, check crates.io for crates that
implement it.
Feature Flags
| Feature | Description
| ----------------- | -----------
| default-formats | DefaultFormat support for common image formats: AVIF, BMP, EXR, FF, GIF, HDR, ICO, JPEG, PNG, PNM, QOI, TGA, TIFF, and WebP
| rayon | DefaultEnables multi-threading with rayon context in some dependencies
| nasm | Enables the build-time use of nasm for ravif, requires nasm installed
| color_quant | Includes color_quant as an implementation of imageops::ColorMap
| avif-native | Enables non-Rust dependencies of avif (mp4parse and dav1d)
| serde | Enables serde integration for various structs and options
Note: When using image in a library you intend to publish, it is recommended to set default-features = false and then explicitly enable format features that are absolutely necessary. This ensures a smaller dependency tree and faster iteration time. The default feature configuration would also enable multithreading which may cause unexpected behavior when running for inherently single-threaded environments such as wasm targets.
Image Types
This crate provides a number of different types for representing images.
Individual pixels within images are indexed with (0,0) at the top left corner.
ImageBuffer
An image parameterised by its Pixel type, represented by a width and height and
a vector of pixels. It provides direct access to its pixels and implements the
GenericImageView and GenericImage traits.
DynamicImage
A DynamicImage is an enumeration over all supported ImageBuffer types.
Its exact image type is determined at runtime. It is the type returned when
opening an image. For convenience DynamicImage reimplements all image
processing functions.
The GenericImageView and GenericImage Traits
Traits that provide methods for inspTop issues
#827DynamicImage->ImageBuffer .. supportable types or streamlining33 comments · 2018-10-20#2472Generics usage by decoders increase code size and compilation time25 comments · 2025-05-24#2358Writing code generic over pixel type is hard20 comments · 2024-10-21#2108Undefined behavior when encoding AVIF image20 comments · 2024-01-15#1118RFC: Rethink GenericImage 20 comments · 2020-01-24#1523Let's talk about `Pixel`18 comments · 2021-08-01#2383Bulk processed pixel conversions15 comments · 2024-11-18#1184no_std support14 comments · 2020-04-03
Discussions
#3123Reviewing old PRs1 comments · 2026-10-10#2997Are decoded pixel values deterministic across machines and crate versions?1 comments · 2026-05-28#2927How to contribute an encoder/decoder to the project?1 comments · 2026-04-27#2873Camera1 comments · 2026-03-18#2851Does and should this library support images with subpixel types that are signed integers?1 comments · 2026-03-14#2847How to implement a function per primitive type?1 comments · 2026-03-12#2776Chromium starting field trials of Rust BMP using image crate2 comments · 2026-02-20#2775Perceptual Image Compression1 comments · 2026-02-18