Skip to content

Commit 3a76b1f

Browse files
authored
fix: Keep aspect ratio of uploaded images if only one of width or height is set. (#150)
1 parent e5c459c commit 3a76b1f

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

djangocms_frontend/contrib/image/models.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,11 @@ def get_size(self, width=None, height=None):
3030

3131
# calculate height when not given according to the
3232
# golden ratio or fallback to the image size
33+
picture_ratio = self.rel_image.width / self.rel_image.height if self.rel_image else PICTURE_RATIO
3334
if not height and width:
34-
height = width / PICTURE_RATIO
35+
height = width / picture_ratio
3536
elif not width and height:
36-
width = height * PICTURE_RATIO
37+
width = height * picture_ratio
3738
elif not width and not height and getattr(self, "picture", None):
3839
if self.rel_image:
3940
width = self.rel_image.width

0 commit comments

Comments
 (0)