Skip to content

Commit fc253fe

Browse files
committed
Don't resize images that are the same size
1 parent d72a01d commit fc253fe

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

system/ui/lib/application.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -287,22 +287,25 @@ def _load_image_from_path(self, image_path: str, width: int | None = None, heigh
287287
rl.image_alpha_premultiply(image)
288288

289289
if width is not None and height is not None:
290+
same_dimensions = image.width == width and image.height == height
291+
290292
# Resize with aspect ratio preservation if requested
291-
if keep_aspect_ratio:
292-
orig_width = image.width
293-
orig_height = image.height
293+
if not same_dimensions:
294+
if keep_aspect_ratio:
295+
orig_width = image.width
296+
orig_height = image.height
294297

295-
scale_width = width / orig_width
296-
scale_height = height / orig_height
298+
scale_width = width / orig_width
299+
scale_height = height / orig_height
297300

298-
# Calculate new dimensions
299-
scale = min(scale_width, scale_height)
300-
new_width = int(orig_width * scale)
301-
new_height = int(orig_height * scale)
301+
# Calculate new dimensions
302+
scale = min(scale_width, scale_height)
303+
new_width = int(orig_width * scale)
304+
new_height = int(orig_height * scale)
302305

303-
rl.image_resize(image, new_width, new_height)
304-
else:
305-
rl.image_resize(image, width, height)
306+
rl.image_resize(image, new_width, new_height)
307+
else:
308+
rl.image_resize(image, width, height)
306309
else:
307310
assert keep_aspect_ratio, "Cannot resize without specifying width and height"
308311
return image

0 commit comments

Comments
 (0)