4 releases

0.3.1 Feb 8, 2024
0.2.2 May 2, 2022
0.2.1 Apr 30, 2022
0.2.0 Apr 24, 2022

#103 in Images

Download history 1638/week @ 2024-07-29 1811/week @ 2024-08-05 3846/week @ 2024-08-12 2081/week @ 2024-08-19 3005/week @ 2024-08-26 2750/week @ 2024-09-02 2653/week @ 2024-09-09 1728/week @ 2024-09-16 1927/week @ 2024-09-23 1859/week @ 2024-09-30 3719/week @ 2024-10-07 2485/week @ 2024-10-14 2946/week @ 2024-10-21 2401/week @ 2024-10-28 2451/week @ 2024-11-04 2062/week @ 2024-11-11

10,100 downloads per month

MIT license

42KB
912 lines

imsz

Test Status License ReferenceC API

Get width and height from an image file reading as few bytes as possible.

This is a fork of scardine/imsz that adds support for more file formats, but also breaks API compatibility in order to be more idiomatic Rust. It also provides a C library wrapper. For more information on how this started see the mentioned link.

The library itself has zero dependencies, but the example binary uses clap.

Usage

There is a simple example binary:

$ cargo run -q --example imsz testdata/image.gif
testdata/image.gif: GIF, 32 x 16

$ cargo run -q --example imsz -- --help
imsz 0.3.0
Paulo Scardine <paulo@scardine.com.br>, Mathias Panzenböck <grosser.meister.morti@gmx.net>

USAGE:
    imsz [FILES]...

ARGS:
    <FILES>...    

OPTIONS:
    -h, --help       Print help information
    -V, --version    Print version information

The relevant parts:

use imsz::imsz;

let info = imsz(filename)?;
println!("{}: {}, {} x {}", filename, info.format, info.width, info.height);
// testdata/image.gif: GIF, 32 x 16

// or for already opened files:
let info = imsz(File::open(filename)?);

// or for in memory buffers:
let info = imsz(b"\x89PNG\r\n\x1a\n...");

// or for *anything* implementing Read and Seek:
use imsz::imsz_from_reader;

let mut file = BufReader::new(File::open(filename)?);
let info = imsz_from_reader(&mut file)?;

Supported File Formats

  • AVIF
  • BMP
  • DDS
  • DIB
  • GIF
  • HEIC/HEIF
  • ICO
  • JPEG
  • JPEG 2000
  • PCX
  • PNG
  • PSD
  • OpenEXR
  • QOI
  • TGA
  • TIFF
  • VTF
  • WEBP
  • XCF

No guarantees of correct or complete implementation are made.

No runtime deps