Repository navigation
EPS Image conversion fails after upgrading to 11.2.1 / 11.3.0 from 10.4.0 #9210
Description
Activity
Without an image to directly test on, this might not be a simple process.
Could you run this code and provide the traceback? It should provide a more specific error.
from PIL import EpsImagePlugin EpsImagePlugin.EpsImageFile(inFile)
Seems like the file is corrupted...
Traceback (most recent call last): File "xxx", line 5, in <module> EpsImagePlugin.EpsImageFile(inFile) File "xxx\Lib\site-packages\PIL\ImageFile.py", line 147, in __init__ self._open() File "xxx\Lib\site-packages\PIL\EpsImagePlugin.py", line 272, in _open raise SyntaxError(msg) SyntaxError: not an EPS file
Thanks. So the error from that line occurs because there is an EPS comment that is longer than 255 characters.
Pillow/src/PIL/EpsImagePlugin.py
Lines 265 to 272 in 0013f95
# ASCII/hexadecimal lines in an EPS file must not exceed # 255 characters, not including line ending characters if bytes_read >= 255: # only enforce this for lines starting with a "%", # otherwise assume it's binary data if byte_arr[0] == ord("%"): msg = "not an EPS file" raise SyntaxError(msg) The strange part is that isn't immediately obvious why that wouldn't have failed for you in 10.4.0.
Could you test Pillow 11.0.0 and 11.1.0 to see exactly which Pillow version the failure starts with?
11.0.0 and 11.1.0 are also not working...
I tried also again with 10.4.0 and there its working.
So with our files its:
11.3.0 - 11.0.0 => not working
10.4.0 => workingTalked to my boss and got a .eps which I'm allowed to share with you.
Had to zip it because eps is not supported on github.Thanks very much.
#8281 was change in behaviour. https://github.com/python-pillow/Pillow/pull/8281/files#diff-c43e9ae25942c60787ebabdbfabddf8618c31d166f93520ea22c8547957f7e9eL337 meant that previously, Pillow stopped reading once the image data was found. Now, it continues reading, encounters "%%BeginBinary", and mistakes some of the data inside for a comment.
If you want an immediate solution, without waiting for a PR and a Pillow release, you could just trim it from the data that Pillow receives.
from PIL import Image from io import BytesIO with open("test.eps", "rb") as fp: b = BytesIO(fp.read().split(b"%%BeginBinary")[0]) im = Image.open(b)
Thanks for the explanation I will take this to the team and we will find a solution until the PR goes throught 😄
Thank you for your fast help ❤️I've created #9211 to resolve this.
Reacted by Lennert Pfundtner
What did you do?
In our company we use Pillow 11.2.1 to convert EPS images to JPG and faced issues with some of the EPS files.
When i tried it locally with Pillow 10.4.0 the conversion worked fine.
As soon as i upgraded to Pillow 11.3.0 the conversion also failed on my local environment.
What did you expect to happen?
Expected output is an .jpg image from an input .eps file
What actually happened?
Our script fails as soon as it hits the "with (Image.open(inFile) as im):"
Error:
"path/to/image.eps" : cannot identify image file "path/to/image.eps"
What are your OS, Python and Pillow versions?
Unfortunately i cannot provide any image the script is failing on because of company terms.