python图像库保存功能 [英] python imaging library save function
问题描述
我刚刚使用python图像库(PIL)完成了一些图像处理,但无法使save函数正常工作.整个代码工作正常,但不会保存生成的图像.代码如下:
I have just done some image processing using the python image library (PIL) and I can't get the save function to work. the whole code works fine but it just wont save the resulting image. The code is below:
im=Image.new("rgb",(200,10),"#ddd")
draw=Image.draw.draw(im)
draw.text((10,10),"run away",fill="red")
im.save("g.jpeg")
保存时会出现错误,因为扩展名未知,甚至删除点也无济于事.
Saving gives an error as unknown extension and even removing the dot doesn't help.
推荐答案
使用.jpg
:
im.save("g.jpg")
图像库确定扩展名要使用哪种编码器,但是在某些版本的PIL中,JPEG编码器不注册.jpeg
扩展名,而仅注册.jpg
.
The image library determines what encoder to use by the extension, but in certain versions of PIL the JPEG encoder do not register the .jpeg
extension, only .jpg
.
另一种可能性是您的PIL安装根本不支持JPEG ;例如,尝试将图像另存为PNG.
Another possibility is that your PIL installation doesn't support JPEG at all; try saving the image as a PNG, for example.
这篇关于python图像库保存功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!