Skip to content

Commit c0e7841

Browse files
committed
refactor: Move the definition of the target_wh-variable
to the only part of the function where it is used.
1 parent 2b93e85 commit c0e7841

1 file changed

Lines changed: 10 additions & 7 deletions

File tree

src/blob.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -388,14 +388,9 @@ impl<'a> BlobObject<'a> {
388388
_ => img,
389389
};
390390

391-
// max_wh is the maximum image width and height, i.e. the resolution-limit.
392-
// target_wh target-resolution for resizing the image.
391+
// max_wh is the maximum image width and height, i.e. the resolution-limit,
392+
// as set by `Config::MediaQuality`.
393393
let exceeds_wh = img.width() > max_wh || img.height() > max_wh;
394-
let mut target_wh = if exceeds_wh {
395-
max_wh
396-
} else {
397-
max(img.width(), img.height())
398-
};
399394
let exceeds_max_bytes = nr_bytes > max_bytes as u64;
400395

401396
let jpeg_quality = 75;
@@ -434,6 +429,14 @@ impl<'a> BlobObject<'a> {
434429
});
435430

436431
if do_scale {
432+
// target_wh will be used as the target-resolution for resizing the image,
433+
// so that the longest sides of the image match the target-resolution.
434+
let mut target_wh = if exceeds_wh {
435+
max_wh
436+
} else {
437+
max(img.width(), img.height())
438+
};
439+
437440
loop {
438441
if mem::take(&mut add_white_bg) {
439442
self::add_white_bg(&mut img);

0 commit comments

Comments
 (0)