mirror of
https://git.asonix.dog/asonix/pict-rs.git
synced 2024-11-28 12:31:00 +00:00
Use sample for thumbnail generation
This commit is contained in:
parent
5e8f369b11
commit
eb685f99e7
3 changed files with 12 additions and 4 deletions
3
Cargo.lock
generated
3
Cargo.lock
generated
|
@ -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",
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue