您的位置:首页 > Web前端

PIL for construct a Image file from STRING or BUFFER

2009-09-15 16:46 633 查看
Can invoke Image.fromstring() to construct a Image file, but need NOTE that:

Image.fromstring() only decodes pixel data, not entire imgages. If the string contain an entire image file, wrap it in a StringIO object, and use Image.open() to load it.

For Example:

]import urllib
import StringIO
from PIL import Image
content = urllib.urlopen("http://www.xxxx.com/aimage.bmp")
data = content.read()
strBuf = StringIO.StringIO(data)
#img = Image.fromstring("RGB", (39,11), data)
#img = img.transpose(Image.FLIP_TOP_BOTTOM)
img = Image.open(strBuf, 'r')
img.save("from_url.bmp", "BMP")
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐