Skip to content

Commit

Permalink
Fix cropping also happening for mode fit
Browse files Browse the repository at this point in the history
  • Loading branch information
pohlm01 committed Nov 27, 2024
1 parent 00d244c commit fad7180
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 3 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "image_thumbs"
version = "0.4.1"
version = "0.4.2"
edition = "2021"
repository = "https://github.com/tweedegolf/image-thumbs"
keywords = ["GCS", "image", "thumbnails"]
Expand All @@ -20,10 +20,8 @@ name = "basic"
object_store = { version = "0.11.0", features = ["gcp"] }
image = { version = "0.25", default-features = false, features = ["png", "jpeg"] }
config = { version = "0.14", default-features = false, features = ["yaml"] }
thiserror = "1.0"
thiserror = "2.0"
serde = { version = "1.0", features = ["derive"] }
tokio = { version = "1.32", features = ["full"] }
bytes = "1.5"
futures = "0.3"
tokio = { version = "1.41", features = ["full"] }
mime = "0.3"
sequential-test = "0.2"
16 changes: 9 additions & 7 deletions src/image.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ impl<T: ObjectStore> ImageThumbs<T> {
force_override: bool,
center: (f32, f32),
) -> ThumbsResult<Vec<ImageDetails>> {

let image = load_from_memory_with_format(&bytes, format)?;

let mut res = Vec::with_capacity(self.settings.len());
for params in self.settings.iter() {
let image = crop_aspect_ratio_with_center(&image, params.size, center);

let naming_pattern = params
.naming_pattern
.clone()
Expand All @@ -50,11 +49,14 @@ impl<T: ObjectStore> ImageThumbs<T> {

let thumbnail = match params.mode {
Mode::Fit => image.thumbnail(params.size.0, params.size.1),
Mode::Crop => image.resize_to_fill(
params.size.0,
params.size.1,
imageops::FilterType::Nearest,
),
Mode::Crop => {
let image = crop_aspect_ratio_with_center(&image, params.size, center);
image.resize_to_fill(
params.size.0,
params.size.1,
imageops::FilterType::Nearest,
)
},
};

match format {
Expand Down

0 comments on commit fad7180

Please sign in to comment.