Skip to content

Commit

Permalink
Limit TIFF strip size when saving with libtiff
Browse files Browse the repository at this point in the history
  • Loading branch information
kmilos committed Jun 2, 2021
1 parent 22e1fff commit 820997e
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/PIL/TiffImagePlugin.py
Expand Up @@ -1553,8 +1553,13 @@ def _save(im, fp, filename):
ifd[COLORMAP] = tuple(v * 256 for v in lut)
# data orientation
stride = len(bits) * ((im.size[0] * bits[0] + 7) // 8)
ifd[ROWSPERSTRIP] = im.size[1]
rows_per_strip = im.size[1]
strip_byte_counts = stride * im.size[1]
# aim for 64 KB strips
while strip_byte_counts > 2 ** 16 and rows_per_strip > 1:
rows_per_strip = (rows_per_strip + 1) // 2
strip_byte_counts = stride * rows_per_strip
ifd[ROWSPERSTRIP] = rows_per_strip
if strip_byte_counts >= 2 ** 16:
ifd.tagtype[STRIPBYTECOUNTS] = TiffTags.LONG
ifd[STRIPBYTECOUNTS] = strip_byte_counts
Expand Down

0 comments on commit 820997e

Please sign in to comment.