作为我正在制作的图像识别程序的一部分,我需要将.ps文件转换为.png文件。我知道我可以使用Ghostscript或其他程序,但是有人可以举一个具体的例子来写这样的东西:
def ps_to_png(ps_file):
file = ghostscript.read(ps_file)
png_file = ghostscript.save(file, "png")
return png_file
(此代码是伪代码,我想知道如何编写实际执行此代码看起来将要执行的操作的代码。)提前致谢! Stack是一个很棒的社区,我对此表示赞赏。
编辑(尝试的解决方案):运行此行时:
os.system("ghostscript file.ps file.png")
我收到以下错误:
'ghostscript' is not recognized as an internal or external command, operable program or batch file.
[尝试使用枕头时:
from PIL import Image
def convert_to_png(ps_file):
img = Image.open(ps_file)
img.save("img.png")
我收到以下错误:
OSError: Unable to locate Ghostscript on paths
您可以使用枕头。
from PIL import Image
psimage=Image.open('myImage.ps')
psimage.save('myImage.png')