我有一个这样的 EPS 文件: https://gofile.io/d/Kv2cwo
通过 Pillow 转换为 png 时,我得到以下结果:
from PIL import Image
eps_image = Image.open("raw.eps")
eps_image.load(scale=10)
eps_image.save("png.png")
它绝对是光栅化的 - 因为 PIL 正在进行光栅化。 在 Adobe Illustrator 中进行转换时,我得到以下信息:
那么我怎样才能在Python中实现这一点呢?
致以最诚挚的问候, 马丁
我尝试回答你的问题,但我不断收到此错误消息:
Traceback (most recent call last):
File "/Users/zhifengzhong/Desktop/西瓜/代码文件/convert.py", line 3, in <module>
eps_image.load(scale=10)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/PIL/EpsImagePlugin.py", line 406, in load
self.im = Ghostscript(self.tile, self.size, self.fp, scale, transparency)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/PIL/EpsImagePlugin.py", line 144, in Ghostscript
subprocess.check_call(command, startupinfo=startupinfo)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 408, in check_call
retcode = call(*popenargs, **kwargs)
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 389, in call
with Popen(*popenargs, **kwargs) as p:
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 1026, in __init__
self._execute_child(args, executable, preexec_fn, close_fds,
File "/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/subprocess.py", line 1824, in _execute_child
and os.path.dirname(executable)
File "<frozen posixpath>", line 152, in dirname
TypeError: expected str, bytes or os.PathLike object, not bool
但是我可以通过 Python Launcher 运行它,并且在 Mac 终端中得到这个:
cd '/Users/zhifengzhong/Desktop/西瓜/代码文件/' && '/usr/local/bin/python3' -d '/Users/zhifengzhong/Desktop/西瓜/代码文件/convert.py' && echo Exit status: $? && exit 1
<PIL.EpsImagePlugin.EpsImageFile image mode=RGB size=912x257 at 0x104FC4910>
is[('eps', (0, 0, 912, 257), 0, (7443, [0, 0, 912, 257]))],(912, 257),<_io.BufferedReader name='/Users/zhifengzhong/Desktop/state.eps'>,10andFalse
<PIL.EpsImagePlugin.EpsImageFile image mode=RGB size=9120x2570 at 0x104FC4910>
<PIL.EpsImagePlugin.EpsImageFile image mode=RGB size=9120x2570 at 0x104FC4910>
Exit status: 0
Saving session...
...copying shared history...
...saving history...truncating history files...
...completed.
Deleting expired sessions... 38 completed.
[Process completed]
我的代码是这样的:
from PIL import Image
eps_image = Image.open("/Users/zhifengzhong/Desktop/state.eps")
eps_image.load(scale=10)
eps_image.save("/Users/zhifengzhong/Desktop/ppg.png")
为什么我无法在Python IDLE中运行它? 我该如何解决这个问题?