Skip to content

Commit

Permalink
Merge pull request #751 from kaj/dimensions-in-thumbnail
Browse files Browse the repository at this point in the history
Dry and consistent size calculation.
  • Loading branch information
bvssvni committed Apr 18, 2018
2 parents 529ad81 + db18c96 commit 47994be
Showing 1 changed file with 1 addition and 14 deletions.
15 changes: 1 addition & 14 deletions src/dynimage.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,20 +288,7 @@ impl DynamicImage {
nwidth: u32,
nheight: u32) -> DynamicImage {

let (width, height) = self.dimensions();

let ratio = width as f32 / height as f32;
let nratio = nwidth as f32 / nheight as f32;

let scale = if nratio > ratio {
nheight as f32 / height as f32
} else {
nwidth as f32 / width as f32
};

let width2 = (width as f32 * scale) as u32;
let height2 = (height as f32 * scale) as u32;

let (width2, height2) = resize_dimensions(self.width(), self.height(), nwidth, nheight, false);
self.thumbnail_exact(width2, height2)
}

Expand Down

0 comments on commit 47994be

Please sign in to comment.