Don't resize images that are the same size

retune-the-third
Shane Smiskol 1 day ago
parent d72a01d739
commit fc253fe1ee
  1. 27
      system/ui/lib/application.py

@ -287,22 +287,25 @@ class GuiApplication:
rl.image_alpha_premultiply(image) rl.image_alpha_premultiply(image)
if width is not None and height is not None: if width is not None and height is not None:
same_dimensions = image.width == width and image.height == height
# Resize with aspect ratio preservation if requested # Resize with aspect ratio preservation if requested
if keep_aspect_ratio: if not same_dimensions:
orig_width = image.width if keep_aspect_ratio:
orig_height = image.height orig_width = image.width
orig_height = image.height
scale_width = width / orig_width scale_width = width / orig_width
scale_height = height / orig_height scale_height = height / orig_height
# Calculate new dimensions # Calculate new dimensions
scale = min(scale_width, scale_height) scale = min(scale_width, scale_height)
new_width = int(orig_width * scale) new_width = int(orig_width * scale)
new_height = int(orig_height * scale) new_height = int(orig_height * scale)
rl.image_resize(image, new_width, new_height) rl.image_resize(image, new_width, new_height)
else: else:
rl.image_resize(image, width, height) rl.image_resize(image, width, height)
else: else:
assert keep_aspect_ratio, "Cannot resize without specifying width and height" assert keep_aspect_ratio, "Cannot resize without specifying width and height"
return image return image

Loading…
Cancel
Save