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

EPS files are loaded without transparency #5619

Closed
yngvem opened this issue Jul 18, 2021 · 1 comment · Fixed by #5620
Closed

EPS files are loaded without transparency #5619

yngvem opened this issue Jul 18, 2021 · 1 comment · Fixed by #5620

Comments

@yngvem
Copy link

yngvem commented Jul 18, 2021

EPS files can have transparency, and GhostScript have the option to keep it. However, if we use Pillow to open an EPS-file, then the alpha-channel is discarded. To my understanding, this is because Pillow is currently using the ppm (portable pixel map)-driver, which creates RGB-images, not RGBA-images.

I therefore propose to add an option to specify which driver to use with GhostScript (or add a flag that can be enabled to use the pngalpha driver instead of the ppmraw driver)

To my understanding, this can be fixed by modifying line 120 in src/PIL/EpsImagePlugin.py:

"-sDEVICE=ppmraw", # ppm driver

into

        "-sDEVICE=pngalpha",  # png driver

I made the change locally on my machine, and it seemed to work well.

What are your OS, Python and Pillow versions?

  • OS: Windows 10
  • Python: 3.8
  • Pillow: 8.2.0

Endnote: Script to generate a postscript file and convert it with Pillow

import turtle
from PIL import Image

pen = turtle.Turtle()
for side in range(4):
    pen.forward(50)
    pen.right(90)

turtle.getscreen().getcanvas().postscript(file="square.eps")
img = Image.open('square.eps')
img.save("image.png")
@radarhere
Copy link
Member

radarhere commented Jul 18, 2021

Thanks for finding a solution to your problem - I've created PR #5620

With that, you would

img = Image.open('square.eps')
img.load(transparency=True)
img.save("image.png")

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

Successfully merging a pull request may close this issue.

2 participants