refactor: Move the definition of the target_wh-variable

to the only part of the function where it is used.
This commit is contained in:
72374
2026-02-03 18:45:00 +01:00
committed by iequidoo
parent e14151d6cc
commit 456891a0af

View File

@@ -389,14 +389,9 @@ impl<'a> BlobObject<'a> {
_ => img,
};
// max_wh is the maximum image width and height, i.e. the resolution-limit.
// target_wh target-resolution for resizing the image.
// max_wh is the maximum image width and height, i.e. the resolution-limit,
// as set by `Config::MediaQuality`.
let exceeds_wh = img.width() > max_wh || img.height() > max_wh;
let mut target_wh = if exceeds_wh {
max_wh
} else {
max(img.width(), img.height())
};
let exceeds_max_bytes = nr_bytes > max_bytes as u64;
let jpeg_quality = 75;
@@ -435,6 +430,14 @@ impl<'a> BlobObject<'a> {
});
if do_scale {
// target_wh will be used as the target-resolution for resizing the image,
// so that the longest sides of the image match the target-resolution.
let mut target_wh = if exceeds_wh {
max_wh
} else {
max(img.width(), img.height())
};
loop {
if mem::take(&mut add_white_bg) {
self::add_white_bg(&mut img);