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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions lib/matplotlib/backends/backend_agg.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,14 +625,24 @@ def print_jpg(self, filename_or_obj, *args, **kwargs):

# add TIFF support
def print_tif(self, filename_or_obj, *args, **kwargs):
"""
Other Parameters
----------------
compression : 'tiff_deflate', 'tiff_adobe_deflate', 'tiff_lzw',
and other values allowed by LIBTIFF_CORE.
If present, indicates the compression algorithm that
will be passed to the backend to save the image.
"""
buf, size = self.print_to_buffer()
if kwargs.pop("dryrun", False):
return
image = Image.frombuffer('RGBA', size, buf, 'raw', 'RGBA', 0, 1)
dpi = (self.figure.dpi, self.figure.dpi)
return image.save(filename_or_obj, format='tiff',
dpi=dpi)
#add TIFF compression support by passing the parameter to backend
compression = kwargs.pop("compression", None)
return image.save(filename_or_obj, format='tiff', dpi=dpi,
compression=compression)

print_tiff = print_tif


FigureCanvas = FigureCanvasAgg