2
0
Fork 0
mirror of https://git.asonix.dog/asonix/pict-rs synced 2024-11-20 11:21:14 +00:00

Use sample for thumbnail generation

This commit is contained in:
asonix 2020-06-16 21:05:06 -05:00
parent 5e8f369b11
commit eb685f99e7
3 changed files with 12 additions and 4 deletions

3
Cargo.lock generated
View file

@ -1188,8 +1188,7 @@ checksum = "7d947cbb889ed21c2a84be6ffbaebf5b4e0f4340638cba0444907e38b56be084"
[[package]]
name = "magick_rust"
version = "0.14.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ef1258fe816e2f16c40532a167718321ec78178984a08b62fca6f6a45784bd33"
source = "git+https://git.asonix.dog/asonix/magick-rust#c5c4c68dcee9947c0975e2831f0a5c32a3ebea66"
dependencies = [
"bindgen",
"libc",

View file

@ -20,7 +20,7 @@ base64 = "0.12.1"
bytes = "0.5"
futures = "0.3.4"
gif = "0.10.3"
magick_rust = "0.14.0"
magick_rust = { version = "0.14.0", git = "https://git.asonix.dog/asonix/magick-rust" }
mime = "0.3.1"
once_cell = "1.4.0"
rand = "0.7.3"

View file

@ -105,7 +105,16 @@ impl Processor for Thumbnail {
let height = wand.get_image_height();
if width > self.0 || height > self.0 {
wand.fit(self.0, self.0);
let width_ratio = width as f64 / self.0 as f64;
let height_ratio = height as f64 / self.0 as f64;
let (new_width, new_height) = if width_ratio < height_ratio {
(width as f64 / height_ratio, self.0 as f64)
} else {
(self.0 as f64, height as f64 / width_ratio)
};
wand.op(|w| w.sample_image(new_width as usize, new_height as usize))?;
Ok(true)
} else if wand.op(|w| w.get_image_format())? == "GIF" {
Ok(true)