nlfiedler / magick-rust

Rust bindings for ImageMagick
https://crates.io/crates/magick_rust
Apache License 2.0
246 stars 63 forks source link

Add support for "thumbnail" image resizing #84

Closed walterbm closed 2 years ago

walterbm commented 2 years ago

This PR adds support for the ImageMagick "thumbnail" resizing operation (MagickThumbnailImage) which resizes images using some optimizations (like removing any associated profiles) to produce small low cost thumbnail images suited for display on the web.

These "thumbnail" images are often a bit smaller than the images produced by the standard resize. For example I ran one of the test images in this repo through both the standard resizing and "thumbnail" resizing:

$> identify IMG_5745*

IMG_5745.JPG JPEG 512x384 512x384+0+0 8-bit sRGB 107302B 0.000u 0:00.001
IMG_5745_resize.JPG JPEG 256x192 256x192+0+0 8-bit sRGB 34504B 0.000u 0:00.000
IMG_5745_thumbnail.JPG JPEG 256x192 256x192+0+0 8-bit sRGB 30304B 0.000u 0:00.000

So the "thumbnail" image was roughly ~ 12% smaller compared to the standard resize image which is a big help for web applications.

I am fairly new to Rust so please let me know if you spot any mistakes or would like me to make any changes!

nlfiedler commented 2 years ago

It's Rust, so if it compiles, it most likely works. :) Thanks for the PR.

walterbm commented 2 years ago

@nlfiedler thanks for reviewing and for maintaining this crate!

I've found this crate very useful for a few projects so If I can help contribute with anything else please let me know