Skip to content

Commit

Permalink
fix(image): scale image after it was rotated
Browse files Browse the repository at this point in the history
  • Loading branch information
RouHim committed Nov 24, 2023
1 parent 75fd4f5 commit 31d74ec
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 59 deletions.
100 changes: 50 additions & 50 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 9 additions & 9 deletions src/image_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,15 @@ pub fn adjust_image(
}

// Resize the image to the needed display size
let resized = read_result
.unwrap()
.resize(display_width, display_height, FilterType::Triangle);
let base_image = read_result.unwrap();

// Rotate or flip the image if needed
let fixed_orientation = if let Some(orientation) = image_orientation {
let rotated = match orientation.rotation {
90 => resized.rotate90(),
180 => resized.rotate180(),
270 => resized.rotate270(),
_ => resized,
90 => base_image.rotate90(),
180 => base_image.rotate180(),
270 => base_image.rotate270(),
_ => base_image,
};

if orientation.mirror_vertically {
Expand All @@ -54,12 +52,14 @@ pub fn adjust_image(
rotated
}
} else {
resized
base_image
};

let resized = fixed_orientation.resize(display_width, display_height, FilterType::Triangle);

// Write the image to a buffer
let mut bytes: Vec<u8> = Vec::new();
fixed_orientation
resized
.write_to(&mut Cursor::new(&mut bytes), image::ImageOutputFormat::Png)
.unwrap();
Some(bytes)
Expand Down

0 comments on commit 31d74ec

Please sign in to comment.