Pillow icon indicating copy to clipboard operation
Pillow copied to clipboard

Fix saving MPO with more than one appended image

Open radarhere opened this issue 6 months ago • 0 comments

Resolves #8977

With each new frame that is saved to an MPO image, an offset is added https://github.com/python-pillow/Pillow/blob/086e05f42ff459747c2ceb0e8e046f4b54e4d779/src/PIL/MpoImagePlugin.py#L65-L68 leading to a longer mpentries https://github.com/python-pillow/Pillow/blob/086e05f42ff459747c2ceb0e8e046f4b54e4d779/src/PIL/MpoImagePlugin.py#L81 meaning the IFD becomes longer https://github.com/python-pillow/Pillow/blob/086e05f42ff459747c2ceb0e8e046f4b54e4d779/src/PIL/MpoImagePlugin.py#L85

We rewind and replace the placeholder data with the IFD https://github.com/python-pillow/Pillow/blob/086e05f42ff459747c2ceb0e8e046f4b54e4d779/src/PIL/MpoImagePlugin.py#L87-L89

But the placeholder data only ever has the same number of bytes, regardless of the number of frames. https://github.com/python-pillow/Pillow/blob/086e05f42ff459747c2ceb0e8e046f4b54e4d779/src/PIL/MpoImagePlugin.py#L55

This PR increases the length of the placeholder data as the number of frames increase.

radarhere avatar May 27 '25 11:05 radarhere