Skip to content

Commit 8d0b908

Browse files
NyanHelsingcslzchen
authored andcommitted
Don't resize w/o a target size and check max_size more clearly
1 parent c9bf7f7 commit 8d0b908

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

mfr/extensions/image/export.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,18 @@ def export(self):
4141
else:
4242
image = Image.open(self.source_file_path)
4343

44-
if max_size:
44+
if not (max_size.get('w') or max_size.get('h')):
45+
# If any of the dimensions for the resize aren't defined:
46+
pass
47+
else:
4548
# resize the image to the w/h maximum specified
4649
ratio = min(max_size['w'] / image.size[0], max_size['h'] / image.size[1])
4750
self.metrics.add('ratio', ratio)
4851
if ratio < 1:
49-
image = image.resize((round(image.size[0] * ratio),
50-
round(image.size[1] * ratio)), Image.ANTIALIAS)
52+
image = image.resize(
53+
(round(image.size[0] * ratio), round(image.size[1] * ratio)),
54+
Image.ANTIALIAS
55+
)
5156

5257
# Mode 'P' is for paletted images. They must be converted to RGB before exporting to
5358
# jpeg, otherwise Pillow will throw an error. This is a temporary workaround, as the

0 commit comments

Comments
 (0)