19 releases

new 0.8.8 Nov 4, 2024
0.8.4 Jan 16, 2024
0.8.3 Dec 5, 2023
0.8.2 Sep 21, 2023
0.2.0 Nov 19, 2015

#90 in Images

Download history 4955/week @ 2024-07-17 4306/week @ 2024-07-24 5592/week @ 2024-07-31 8999/week @ 2024-08-07 5643/week @ 2024-08-14 15450/week @ 2024-08-21 11068/week @ 2024-08-28 12318/week @ 2024-09-04 9886/week @ 2024-09-11 12251/week @ 2024-09-18 11963/week @ 2024-09-25 13978/week @ 2024-10-02 8045/week @ 2024-10-09 13226/week @ 2024-10-16 9623/week @ 2024-10-23 11345/week @ 2024-10-30

43,219 downloads per month
Used in 28 crates (19 directly)

MIT license

43KB
768 lines

resize Build Status crates.io

Image resampling library in pure Rust.

Features

  • Fast, with support for many pixel formats
  • No encoders/decoders, meant to be used with some external library
  • Tuned for resizing to the same dimensions multiple times: uses preallocated buffers and matrixes

Usage

use resize::Pixel::RGB8;
use resize::Type::Lanczos3;

// Downscale by 2x.
let (w1, h1) = (640, 480);
let (w2, h2) = (320, 240);
// Don't forget to fill `src` with image data (RGB8).
// This requires Vec<RGB<u8>>. If you have Vec<u8>, then use .as_rgb()/.as_rgb_mut() to reinterpret it as a slice of pixels.
let src = vec![RGB::new(0,0,0); w1*h1];
// Destination buffer. Must be mutable.
let mut dst = vec![RGB::new(0,0,0); w2*h2];
// Create reusable instance.
let mut resizer = resize::new(w1, h1, w2, h2, RGB8, Lanczos3);
// Do resize without heap allocations.
// Might be executed multiple times for different `src` or `dst`.
resizer.resize(&src, &mut dst);

See API documentation for overview of all available methods. See also this example.

Recommendations

Read this and this great articles on image resizing technics and resampling filters. Tldr; (with built-in filters of this library) use Lanczos3 for downscaling, use Mitchell for upscaling. You may also want to downscale in linear colorspace (but not upscale). Gamma correction routines currently not included to the library, but actually quite simple to accomplish manually, see here for some basic theory.

License

  • Library is licensed under MIT
  • Image used in examples is licensed under CC BY-SA 3.0

Dependencies

~1.3–1.7MB
~32K SLoC