简体   繁体   English

如果是EPS格式,则Python PIL Image.save()错误

[英]Python PIL Image.save() error in case of EPS format

I am trying to convert jpeg files to eps ones. 我正在尝试将jpeg文件转换为eps文件。 I am using the following code: 我正在使用以下代码:

fp=open("test.jpg",'rb')
im=Image.open(fp)
outf=open('test2.eps','wb')
im.save(outf, 'EPS')

However, I ma getting the following error: 但是,我可能遇到以下错误:

Traceback (most recent call last):
File "im2eps2.py", line 11, in <module> im.save(outf, 'EPS')
File "C:\Python26\Lib\site-packages\PIL\Image.py", line 1465, in save
save_handler(self, fp, filename)
File "C:\Python26\Lib\site-packages\PIL\EpsImagePlugin.py", line 353, in _save
fp = io.TextIOWrapper(NoCloseStream(fp), encoding='latin-1')
File "C:\Python26\Lib\io.py", line 1429, in __init__
self._seekable = self._telling = self.buffer.seekable()
File "C:\Python26\Lib\site-packages\PIL\EpsImagePlugin.py", line 348, in __getattr__
return getattr(self.fp, name)
AttributeError: 'file' object has no attribute 'seekable'

I shall be thankful for suggestions. 我将感谢您的建议。 Thanks 谢谢

PS: I reinstall PIL from its main page ie http://www.pythonware.com/products/pil/ and it worked :) Earlier, I used windows installer provided by http://www.lfd.uci.edu/~gohlke/pythonlibs . PS:我从其主页(即http://www.pythonware.com/products/pil/)重新安装了PIL,并且可以正常工作:)之前,我使用了http://www.lfd.uci.edu/~提供的Windows安装程序。 gohlke / pythonlibs I think the problem was with the binary that I installed earlier. 我认为问题出在我之前安装的二进制文件上。 Currently, I have 1.1.7 PIL and it is working fine. 目前,我有1.1.7 PIL,并且工作正常。

Thanks 谢谢

According to cgohlke this was a bug in Pillow and has been fixed in 2.4.0, which was released last month (1st April 2014). 根据cgohlke的说法,这是Pillow中的错误,并已在上个月(2014年4月1日)发布的2.4.0中修复。

From the bug report : 错误报告

io.TextIOWrapper expects an object with io.IOBase interface, not a Python 2 file object. io.TextIOWrapper需要一个具有io.IOBase接口的对象,而不是Python 2 file对象。 Using fh = io.open('test.eps', 'wb') passes this stage but io.TextIOWrapper.write() expects unicode strings; 使用fh = io.open('test.eps', 'wb')通过了这个阶段,但是io.TextIOWrapper.write()需要Unicode字符串; the example fails with TypeError: can't write str to text stream . 该示例因TypeError: can't write str to text stream失败TypeError: can't write str to text stream

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM