imageformat 0.1.0

Quick probing of image format without loading the entire file.
Documentation

safe_format

Quickly probe the format of various image formats without reading the entire file.

The goal of this crate is to be able to detect format of a supported image without loading unnecessary data, and without pulling in more dependencies. Most reads only require 16 bytes or less.

Usage

use image_format_detector::prelude::*;

fn main() {
    // Example: Read the first few bytes of a file
    let bytes = std::fs::read("example.png").expect("Failed to read file");
    let format = detect_image_format(&bytes);

    match format {
        ImageFormat::Jpeg => println!("It's a JPEG image."),
        ImageFormat::JpegXl => println!("It's a JPEG XL image."),
        ImageFormat::Png => println!("It's a PNG image."),
        ImageFormat::Webp => println!("It's a WEBP image."),
        ...
    }
}

Supported Image Formats

  • Aseprite
  • Avif
  • BMP
  • DDS
  • EXR
  • Farbfeld
  • GIF
  • HDR
  • HEIC / HEIF
  • ICO*
  • ILBM (IFF)
  • JPEG
  • JPEG XL
  • KTX2
  • PNG
  • PNM (PBM, PGM, PPM)
  • PSD / PSB
  • QOI
  • TGA
  • TIFF
  • VTF
  • WEBP

If you have a format you think should be added, feel free to create an issue.