Skip to content
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

Merged
merged 1 commit into from Sep 10, 2012

Conversation

efiring
Copy link
Member

@efiring efiring commented Sep 9, 2012

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.

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.
@pelson
Copy link
Member

pelson commented Sep 10, 2012

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

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 :)

@dmcdougall
Copy link
Member

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.

efiring added a commit that referenced this pull request Sep 10, 2012
Add dpi kwarg to PIL image.save method for TIFF file.
@efiring efiring merged commit 2a4a949 into matplotlib:master Sep 10, 2012
@efiring
Copy link
Member Author

efiring commented Sep 10, 2012

@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.

@dmcdougall
Copy link
Member

@efiring I can take a look. It's absolutely not release critical though, since it only appears to be metadata. Thanks for your help.

@efiring efiring deleted the fix_tiff_dpi branch May 29, 2013 02:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants