[][src]Crate image

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 io::Reader:

use image::io::Reader as ImageReader;

let img = ImageReader::open("myimage.png")?.decode()?;
let img2 = ImageReader::new(Cursor::new(bytes)).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 bytes, image::ImageOutputFormat::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 supported ImageBuffer 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 a GenericImage.
  • flat module containing types for interoperability with generic channel matrices and foreign interfaces.

Low level encoding/decoding API

The ImageDecoder and ImageDecoderExt 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 DynamicImage::from_decoder.

ImageEncoder provides the analogous functionality for encoding image data.

Re-exports

pub use crate::error::ImageError;
pub use crate::error::ImageResult;
pub use crate::flat::FlatSamples;

Modules

bmpDeprecated

Decoding and Encoding of BMP Images

buffer

Iterators and other auxiliary structure for the ImageBuffer type.

codecs

Encoding and decoding for various image file formats.

ddsDeprecated

Decoding of DDS images

dxtDeprecated

Decoding of DXT (S3TC) compression

error

Contains detailed error representation.

farbfeldDeprecated

Decoding of farbfeld images

flat

Image representations for ffi.

gifDeprecated

Decoding of GIF Images

hdrDeprecated

Decoding of Radiance HDR Images

icoDeprecated

Decoding and Encoding of ICO files

imageops

Image Processing Functions

io

Input and output of images.

jpegDeprecated

Decoding and Encoding of JPEG Images

math

Mathematical helper functions and types.

pngDeprecated

Decoding and Encoding of PNG Images

pnmDeprecated

Decoding and Encoding of netpbm image formats (pbm, pgm, ppm and pam)

tgaDeprecated

Decoding and Encoding of TGA Images

tiffDeprecated

Decoding and Encoding of TIFF Images

webpDeprecated

Decoding of WebP Images

Structs

Bgr

BGR colors

Bgra

BGR colors + alpha channel

Delay

The delay of a frame relative to the previous one.

Frame

A single animation frame

Frames

An implementation dependent iterator, reading the frames as requested

ImageBuffer

Generic image buffer

Luma

Grayscale colors

LumaA

Grayscale colors + alpha channel

Pixels

Immutable pixel iterator

Progress

Represents the progress of an image operation.

Rgb

RGB colors

Rgba

RGB colors + alpha channel

SubImage

A View into another image

Enums

ColorType

An enumeration over supported color types and bit depths

DynamicImage

A Dynamic Image

ExtendedColorType

An enumeration of color types encountered in image formats.

ImageFormat

An enumeration of supported image formats. Not all formats support both encoding and decoding.

ImageOutputFormat

An enumeration of supported image formats for encoding.

Traits

AnimationDecoder

AnimationDecoder trait

EncodableLayout

Types which are safe to treat as an immutable byte slice in a pixel layout for image encoding.

GenericImage

A trait for manipulating images.

GenericImageView

Trait to inspect an image.

ImageDecoder

The trait that all decoders implement

ImageDecoderExt

Specialized image decoding not be supported by all formats

ImageEncoder

The trait all encoders implement

Pixel

A generalized pixel.

Primitive

Primitive trait from old stdlib

Functions

guess_format

Guess image format from memory block

image_dimensions

Read the dimensions of the image located at the specified path. This is faster than fully loading the image and then getting its dimensions.

load

Create a new image from a Reader

load_from_memory

Create a new image from a byte slice

load_from_memory_with_format

Create a new image from a byte slice

open

Open the image located at the path specified. The image's format is determined from the path's file extension.

save_buffer

Saves the supplied buffer to a file at the path specified.

save_buffer_with_format

Saves the supplied buffer to a file at the path specified in the specified format.

Type Definitions

GrayAlphaImage

Sendable grayscale + alpha channel image buffer

GrayImage

Sendable grayscale image buffer

RgbImage

Sendable Rgb image buffer

RgbaImage

Sendable Rgb + alpha channel image buffer