Skip to content

Commit c9bf7f7

Browse files
NyanHelsingcslzchen
authored andcommitted
Pull image dimensions out of paths more robustly
1 parent 7e1e187 commit c9bf7f7

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

mfr/extensions/image/export.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,16 @@ def __init__(self, *args, **kwargs):
1919
def export(self):
2020
parts = self.format.split('.')
2121
type = parts[-1].lower()
22-
max_size = [int(x) for x in parts[0].split('x')] if len(parts) == 2 else None
22+
max_size = {
23+
'w': None,
24+
'h': None
25+
}
26+
if len(parts) == 2:
27+
max_size['w'], max_size['h'] = [int(size) for size in parts[0].split('x')]
2328
self.metrics.merge({
2429
'type': type,
25-
'max_size_w': max_size[0],
26-
'max_size_h': max_size[1],
30+
'max_size_w': max_size['w'],
31+
'max_size_h': max_size['h'],
2732
})
2833
try:
2934
if self.ext in ['.psd']:
@@ -38,7 +43,7 @@ def export(self):
3843

3944
if max_size:
4045
# resize the image to the w/h maximum specified
41-
ratio = min(max_size[0] / image.size[0], max_size[1] / image.size[1])
46+
ratio = min(max_size['w'] / image.size[0], max_size['h'] / image.size[1])
4247
self.metrics.add('ratio', ratio)
4348
if ratio < 1:
4449
image = image.resize((round(image.size[0] * ratio),

0 commit comments

Comments
 (0)