Skip to content

Conversation

@radarhere
Copy link
Member

When opening an image, if the size is missing, EpsImagePlugin sets the image size just before throwing an error.

if not self._size:
self._size = 1, 1 # errors if this isn't set. why (1,1)?
msg = "cannot determine EPS bounding box"
raise OSError(msg)

But if an error is thrown when opening, there is no image afterwards. Consider this example code, derived from the test suite.

import io
from PIL import Image

data = io.BytesIO(b'%!PS-Adobe-3.0 EPSF-3.0\n%%BoundingBox: a b c d\n10 setlinewidth\n10 10 moveto\n0 90 rlineto 90 0 rlineto 0 -90 rlineto closepath\nstroke')
try:
    im = Image.open(data)
except OSError:
    pass
print(im)

gives

Traceback (most recent call last):
  File "demo.py", line 9, in <module>
    print(im)
NameError: name 'im' is not defined

So if there is no image afterwards, why does it need a size? This PR removes the line.

@hugovk hugovk merged commit 0c7061e into python-pillow:main Jun 13, 2023
@radarhere radarhere deleted the eps branch June 13, 2023 21:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants