Compare commits

..

2 commits

View file

@ -1312,21 +1312,18 @@ def get_imgmetadata(
imgwidthpx, imgheightpx = imgdata.size imgwidthpx, imgheightpx = imgdata.size
ndpi = imgdata.info.get("dpi") ndpi = imgdata.info.get("dpi")
# the PNG plugin of PIL adds the undocumented "aspect" field instead of if ndpi is None:
# the "dpi" field if the PNG pHYs chunk unit is not set to meters # the PNG plugin of PIL adds the undocumented "aspect" field instead of
if ( # the "dpi" field if the PNG pHYs chunk unit is not set to meters
ndpi is None if imgformat == ImageFormat.PNG and imgdata.info.get("aspect") is not None:
and imgformat == ImageFormat.PNG aspect = imgdata.info["aspect"]
and imgdata.info.get("aspect") is not None # make sure not to go below the default dpi
): if aspect[0] > aspect[1]:
aspect = imgdata.info["aspect"] ndpi = (default_dpi * aspect[0] / aspect[1], default_dpi)
# make sure not to go below the default dpi else:
if aspect[0] > aspect[1]: ndpi = (default_dpi, default_dpi * aspect[1] / aspect[0])
ndpi = (default_dpi * aspect[0] / aspect[1], default_dpi)
else: else:
ndpi = (default_dpi, default_dpi * aspect[1] / aspect[0]) ndpi = (default_dpi, default_dpi)
else:
ndpi = (default_dpi, default_dpi)
# In python3, the returned dpi value for some tiff images will # In python3, the returned dpi value for some tiff images will
# not be an integer but a float. To make the behaviour of # not be an integer but a float. To make the behaviour of
# img2pdf the same between python2 and python3, we convert that # img2pdf the same between python2 and python3, we convert that