Avoid div-by-zero in fit_image

This commit is contained in:
Kovid Goyal 2023-04-22 07:16:51 +05:30
parent 8ed76a284a
commit 3ac4dc6e43
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -345,6 +345,8 @@ def fit_image(width, height, pwidth, pheight):
@param pheight: Height of box @param pheight: Height of box
@return: scaled, new_width, new_height. scaled is True iff new_width and/or new_height is different from width or height. @return: scaled, new_width, new_height. scaled is True iff new_width and/or new_height is different from width or height.
''' '''
if height < 1 or width < 1:
return False, int(width), int(height)
scaled = height > pheight or width > pwidth scaled = height > pheight or width > pwidth
if height > pheight: if height > pheight:
corrf = pheight / float(height) corrf = pheight / float(height)