New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add dpi kwarg to PIL image.save method for TIFF file. #1226
Conversation
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.
Looks good. +1 |
@@ -1910,7 +1910,9 @@ def print_tif(self, filename_or_obj, *args, **kwargs): | |||
buf, size = agg.print_to_buffer() | |||
if kwargs.pop("dryrun", False): return | |||
image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1) | |||
return image.save(filename_or_obj, format='tiff') | |||
dpi = (self.figure.dpi, self.figure.dpi) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For those who want to look this up: http://www.pythonware.com/library/pil/handbook/format-tiff.htm
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for answering my question before I asked it :)
Is there a similar fix that can be made for png files rendered by the cairo backend? +1 for TIF file fix, though. Works fine on TIFs now. |
Add dpi kwarg to PIL image.save method for TIFF file.
@dmcdougall regarding cairo and png: I looked at the pycairo documentation and did not find any indication that our present code is incorrect. Cairo appears to be correctly getting the dpi and the figure dimensions, but the figure dimensions are being written in the file metadata as if the dpi were 72. It seems that tiff records dpi but not dimensions, and the reverse is true for png. It is possible that the bug is in cairo, although this seems unlikely a priori. If you would like to pursue this, I suggest looking at the pycairo examples (which I have not done at all). If you can find a reasonably simple example that writes to a png file, then you might either see what we need to do differently, or discover that the problem is indeed a cairo bug. |
@efiring I can take a look. It's absolutely not release critical though, since it only appears to be metadata. Thanks for your help. |
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.