image-rs /image

Encoding and decoding images in Rust

★ 5,912⑂ 746👁 77⑃ 1,817● 1,249▤ 0
RustApache-2.0Created 2014-05-25
+2
Daily
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 insp

Top issues

Discussions

Snapshot: 2026-11-16T09:23:14Z · Data license Apache-2.0 · JSON