Skip to content

Commit 39e3636

Browse files
kmiloshugovk
authored andcommitted
Ensure TIFF RowsPerStrip is multiple of 8 for JPEG compression
1 parent c0615e7 commit 39e3636

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/PIL/TiffImagePlugin.py

+3
Original file line numberDiff line numberDiff line change
@@ -1577,6 +1577,9 @@ def _save(im, fp, filename):
15771577
# aim for 64 KB strips when using libtiff writer
15781578
if libtiff:
15791579
rows_per_strip = min((2 ** 16 + stride - 1) // stride, im.size[1])
1580+
# JPEG encoder expects multiple of 8 rows
1581+
if compression == "jpeg":
1582+
rows_per_strip = min(((rows_per_strip + 7) // 8) * 8, im.size[1])
15801583
else:
15811584
rows_per_strip = im.size[1]
15821585
strip_byte_counts = stride * rows_per_strip

0 commit comments

Comments
 (0)