如何将.ps文件转换为.png文件?

编程入门 行业动态 更新时间:2024-10-26 23:37:38
本文介绍了如何将.ps文件转换为.png文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

作为我正在制作的图像识别程序的一部分,我需要将.ps文件转换为.png文件.我知道我可以使用Ghostscript或其他程序,但是有人可以举一个具体的例子来写这样的东西吗:

I need to convert .ps files to .png files as part of an image recognition program I am making. I know I can use Ghostscript or other programs, but could someone give a specific example of how to write something like this:

def ps_to_png(ps_file): file = ghostscript.read(ps_file) png_file = ghostscript.save(file, "png") return png_file

(此代码是伪代码,我想知道如何编写实际执行此代码看起来将要执行的操作的代码.)提前致谢!Stack是一个很棒的社区,我对此表示赞赏.

(This code is pseudo code- I want to know how to write something that actually does what this code looks like it will do.) Thanks in advance! Stack is a great community and I appreciate it.

编辑(尝试的解决方案):在运行此行时:

EDIT (Attempted solutions): When running this line:

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')

如果要将其包装到函数中:

If you want to wrap it to a function:

from PIL import Image def convert_to_png(path): img = Image.open(path) img.save("img.png") path='/path_to_your_file' convert_to_png(path)

更多推荐

如何将.ps文件转换为.png文件?

本文发布于:2023-07-27 00:25:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1219224.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   转换为   如何将   png   ps

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!