Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot identify image file 'xxxx.eps' #7751

Closed
WangZiXiao-ChenDu opened this issue Jan 24, 2024 · 10 comments
Closed

cannot identify image file 'xxxx.eps' #7751

WangZiXiao-ChenDu opened this issue Jan 24, 2024 · 10 comments

Comments

@WangZiXiao-ChenDu
Copy link

WangZiXiao-ChenDu commented Jan 24, 2024

What are your OS, Python and Pillow versions?

  • OS: Windows 11
  • Python: 3.10.9
  • Pillow: 10.2.0
from PIL import Image
try:
   im = Image.open("./input/G14.eps")
   im.load(scale=4)
   im.save("./output/G14.jpg")
except Exception as ex:
      print(ex)
else:
     print("success")

Firstly, I am certain that the code can run normally. In the process of converting EPS to JPG, the majority of the conversions are successful, but there are some instances where it fails. However, the EPS images that fail are not corrupted. I can provide one of the failed images, and I would like to know the reasons for the failures and how to resolve them.
eps_Pic.zip

@radarhere
Copy link
Member

radarhere commented Jan 24, 2024

Looking at G14.eps, it contains data after the EOF marker that is causing it to fail.

Do you know what software was used to create the problem images?

However, the EPS images that fail are not corrupted

How are you sure of this?

@WangZiXiao-ChenDu
Copy link
Author

Thank you for the reply. I can use Aspose to convert images to JPG, so my understanding is that the images are not damaged.
https://products.aspose.app/imaging/zh-hans/conversion/eps-to-jpg

@WangZiXiao-ChenDu
Copy link
Author

WangZiXiao-ChenDu commented Jan 24, 2024

The EPS image has data after the %%EOF marker, but it can still be successfully processed using Pillow.
image

_2QW2L~Q.zip

@radarhere
Copy link
Member

Do you know what software was used to create the problem images?

@WangZiXiao-ChenDu
Copy link
Author

I'm sorry, I didn't create this EPS file, and I'm not sure which software generated it.

@Yay295
Copy link
Contributor

Yay295 commented Jan 24, 2024

II*␀ is the magic number for a (little endian) TIFF file. If you delete everything up to that magic number, you can view the (valid) TIFF images.
tiff_pic.zip

@WangZiXiao-ChenDu
Copy link
Author

II*␀ is the magic number for a (little endian) TIFF file. If you delete everything up to that magic number, you can view the (valid) TIFF images. tiff_pic.zip

II*␀

Can I understand that if I delete the content after %%EOF, it will be a correct EPS file?

@WangZiXiao-ChenDu
Copy link
Author

WangZiXiao-ChenDu commented Jan 25, 2024

The EPS image has data after the %%EOF marker, but it can still be successfully processed using Pillow. image

_2QW2L~Q.zip

I don't understand why this image has similar content after %%EOF, yet it can still be successfully converted to JPG?

@radarhere
Copy link
Member

Can I understand that if I delete the content after %%EOF, it will be a correct EPS file?

Yes. If you would like an immediate solution, you can trim the content after %%EOF like this.

import io
from PIL import Image, EpsImagePlugin
with open("./input/G14.eps", "rb") as fp:
  prefix = fp.read(4)
  if EpsImagePlugin._accept(prefix):
    data = prefix+fp.read()
    im = Image.open(io.BytesIO(data.split(b"%%EOF")[0]+b"%%EOF"))
  else:
    fp.seek(0)
    im = Image.open(fp)
  im.load(scale=4)
  im.save("./output/G14.jpg")

@WangZiXiao-ChenDu
Copy link
Author

Can I understand that if I delete the content after %%EOF, it will be a correct EPS file?

Yes. If you would like an immediate solution, you can trim the content after %%EOF like this.

import io
from PIL import Image, EpsImagePlugin
with open("./input/G14.eps", "rb") as fp:
  prefix = fp.read(4)
  if EpsImagePlugin._accept(prefix):
    data = prefix+fp.read()
    im = Image.open(io.BytesIO(data.split(b"%%EOF")[0]+b"%%EOF"))
  else:
    fp.seek(0)
    im = Image.open(fp)
  im.load(scale=4)
  im.save("./output/G14.jpg")

This method works, thank you so much!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants