Skip to content

Commit c7f997d

Browse files
committed
Add dpi kwarg to PIL image.save method for TIFF file.
This corrects a bug in which the tiff image metadata was set to a default dpi of 72 regardless of the actual dpi. At least some image viewers, including Preview on the Mac, do not use this dpi metadata, even though they can display it, so fixing this bug does not correct the erroneous display of the image on such viewers.
1 parent 1478a1b commit c7f997d

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/matplotlib/backend_bases.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -1910,7 +1910,9 @@ def print_tif(self, filename_or_obj, *args, **kwargs):
19101910
buf, size = agg.print_to_buffer()
19111911
if kwargs.pop("dryrun", False): return
19121912
image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)
1913-
return image.save(filename_or_obj, format='tiff')
1913+
dpi = (self.figure.dpi, self.figure.dpi)
1914+
return image.save(filename_or_obj, format='tiff',
1915+
dpi=dpi)
19141916
print_tiff = print_tif
19151917

19161918
def get_supported_filetypes(self):

0 commit comments

Comments
 (0)