如何使用python pil将gif文件更改为png文件 [英] How to change gif file to png file using python pil
本文介绍了如何使用python pil将gif文件更改为png文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码:
import Image,glob
files = glob.glob("/small/*.gif")
for imageFile in files:
print "Processing: " + imageFile
try:
im = Image.open(imageFile)
im.save( "/small_/", "png" )
except Exception as exc:
print "Error: " + str(exc)
但显示错误:
File "f.py", line 13
im.save( "/small_/", "png" )
^
SyntaxError: invalid syntax
那我该怎么办
谢谢
已更新:
import Image,glob,os
files = glob.glob("small/*.gif")
for imageFile in files:
filepath,filename = os.path.split(imageFile)
filterame,exts = os.path.splitext(filename)
print "Processing: " + imageFile,filterame
im = Image.open(imageFile)
im.save( 'small_/'+filterame+'.png','PNG')
推荐答案
尝试将此处的代码复制并粘贴到编辑器中,对我来说效果很好. 您似乎那里有一些不可打印的字符或类似的字符.
Try copy and pasting your code in here back into your editor, it works perfectly fine for me. You seem to have some non-printable characters in there or something similar.
此外,请查看 PIL文档,
Also, have a look at the PIL documentation, save
needs a filename or fileobject, not a folder.
这篇关于如何使用python pil将gif文件更改为png文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文