JPEGSetupEncode: RowsPerStrip must be multiple of 8 for JPEG error on saving tif using pillow

Viewed 184

I was using pillow (with SIMD) for reading , editing and saving a tif file. The data was edited in opencv and then converted to pil and saved. On saving the file I am getting the following error .

Error

JPEGSetupEncode: RowsPerStrip must be multiple of 8 for JPEG.
Traceback (most recent call last):
  File "/snap/pycharm-community/248/plugins/python-ce/helpers/pydev/_pydevd_bundle/pydevd_exec2.py", line 3, in Exec
    exec(exp, global_vars, local_vars)
  File "<input>", line 1, in <module>
  File "/home/pi/.cache/pypoetry/virtualenvs/sing-TDLtsxZh-py3.8/lib/python3.8/site-packages/PIL/Image.py", line 2235, in save
    save_handler(self, fp, filename)
  File "/home/pi/.cache/pypoetry/virtualenvs/sing-TDLtsxZh-py3.8/lib/python3.8/site-packages/PIL/TiffImagePlugin.py", line 1697, in _save
    raise OSError(f"encoder error {s} when writing image file")
OSError: encoder error -2 when writing image file

Code

import tempfile
from PIL import Image, ImageSequence

with tempfile.NamedTemporaryFile(prefix=f'{uuid4()}', suffix=f'.{fmt}') as tempdoc:
    if fmt in ["tiff", "tif", "pdf"]:
        pills[0].save(tempdoc.name,
                      save_all=True,
                      append_images=pills[1:],
                      optimize=True,
                      quality=10)

Could someone please tell me the possible cause and solution? If I've missed out anything, over- or under-emphasized a specific point, let me know in the comments. Thank you so much in advance for your time.

0 Answers
Related