8000 Added compression option to save TIFF images by renato-umeton · Pull Request #8531 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

Skip to content

Added compression option to save TIFF images #8531

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

Closed
wants to merge 9 commits into from
Closed
Prev Previous commit
Next Next commit
Add comments and better spacing for TIFF LZW
  • Loading branch information
Dana-Farber authored Apr 24, 2017
commit 1ed0ef97317643fc49eb152e38ceff2b8afa69b1
6 changes: 3 additions & 3 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,18 +637,18 @@ def print_tif(self, filename_or_obj, *args, **kwargs):
return
image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)
dpi = (self.figure.dpi, self.figure.dpi)

#add TIFF compression support
compressed = kwargs.pop("compressed", False)
if compressed:
libtiff_original_value = TiffImagePlugin.WRITE_LIBTIFF
Copy link
Member

Choose a reason for hiding this comment

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

Is it ok to simplify this as?

TiffImagePlugin.WRITE_LIBTIFF = compressed

Or are there instances where the user needs TiffImagePlugin.WRITE_LIBTIFF to be True even when writing out a non-compressed image?

Copy link
Author

Choose a reason for hiding this comment

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

Sure, I'll add the test part.

I'd say it is not OK to "simplify" because you may use the flag somewhere else and remain confused about it not getting back to its original state once finished saving the image.

Copy link
Contributor

Choose a reason for hiding this comment

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

Probably better to use try:... finally:... to handle the case where the saving fails.

Copy link
Author

Choose a reason for hiding this comment

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

@story645 I'm having some issues coming up with some meaningful tests since we now do a pull pass-through of the parameters to the backend. Can you suggest some tests, if needed?

Copy link
Member

Choose a reason for hiding this comment

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

Check that the arg is getting passed through properly and that what this function saves out is a valid compressed tiff file (just try one compression arg parameter, does not matter which one).

TiffImagePlugin.WRITE_LIBTIFF = True
return_value = image.save(filename_or_obj, format='tiff',
dpi=dpi, compression='tiff_lzw')
dpi=dpi, compression='tiff_lzw')
TiffImagePlugin.WRITE_LIBTIFF = libtiff_original_value
return return_value
else:
return image.save(filename_or_obj, format='tiff',
dpi=dpi)
dpi=dpi)
print_tiff = print_tif


Expand Down
0