From 39e36368e7d2206cda4bb9cc34973b0b01d52147 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Milo=C5=A1=20Komar=C4=8Devi=C4=87?= <4973094+kmilos@users.noreply.github.com> Date: Wed, 7 Jul 2021 09:38:06 +0200 Subject: [PATCH] Ensure TIFF RowsPerStrip is multiple of 8 for JPEG compression --- src/PIL/TiffImagePlugin.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/PIL/TiffImagePlugin.py b/src/PIL/TiffImagePlugin.py index a5e2bb53d..3f34cc9ac 100644 --- a/src/PIL/TiffImagePlugin.py +++ b/src/PIL/TiffImagePlugin.py @@ -1577,6 +1577,9 @@ def _save(im, fp, filename): # aim for 64 KB strips when using libtiff writer if libtiff: rows_per_strip = min((2 ** 16 + stride - 1) // stride, im.size[1]) + # JPEG encoder expects multiple of 8 rows + if compression == "jpeg": + rows_per_strip = min(((rows_per_strip + 7) // 8) * 8, im.size[1]) else: rows_per_strip = im.size[1] strip_byte_counts = stride * rows_per_strip