13 stable releases

new 3.3.0 Jul 13, 2025
3.2.1 Sep 19, 2024
3.2.0 Aug 30, 2024
3.1.5 Jul 7, 2024
2.12.0 Mar 3, 2019

#686 in Images

Download history 316/week @ 2025-03-23 475/week @ 2025-03-30 405/week @ 2025-04-06 491/week @ 2025-04-13 291/week @ 2025-04-20 239/week @ 2025-04-27 500/week @ 2025-05-04 741/week @ 2025-05-11 533/week @ 2025-05-18 3304/week @ 2025-05-25 3259/week @ 2025-06-01 2875/week @ 2025-06-08 4042/week @ 2025-06-15 3516/week @ 2025-06-22 1839/week @ 2025-06-29 518/week @ 2025-07-06

9,967 downloads per month
Used in 15 crates (7 directly)

GPL-3.0+

425KB
1K SLoC

Load image as sRGB

Glue code for a few libraries that correctly loads a JPEG, PNG, or (optionally) WebP or AVIF image into memory, taking into accout color profile metadata in PNG chunks, EXIF data and app markers. Converts CMYK to RGB if needed.

cargo add load_image
fn main() -> Result<(), Box<dyn std::error::Error>> {
    let path = std::env::args().nth(1).ok_or("Please provide image file path")?;
    let img = load_image::load_image(path)?;
}

The returned Image is:

struct Image {
    pub width: usize,
    pub height: usize,
    pub bitmap: enum ImageData {
        RGB8(Vec<RGB8>),
        RGBA8(Vec<RGBA8>),
        RGB16(Vec<RGB16>),
        RGBA16(Vec<RGBA16>),
        GRAY8(Vec<GRAY8>),
        GRAY16(Vec<GRAY16>),
        GRAYA8(Vec<GRAYA8>),
        GRAYA16(Vec<GRAYA16>),
    }
}

The bitmap is packed, so x + y * width gives the pixel at x,y (use imgref for convenient manipulation).

The load_image function doesn't panic, but if you enable the mozjpeg feature, it will depend on unwinding internally, and won't be compatible with crates compiled with panic = "abort" option.

Dependencies

~2.6–8.5MB
~170K SLoC