使用python PIL库方便的进行多图片格式的转换(原创)
代码简单实用,话就不多说了。直接贴代码:
'''
Ezone 2020-02-16 @tangkin.com
import PIL from Image
def conv_img(covimg_fn,format=""):
'''
cov to any image format
:param covimg_fn:
:param format:
:return:
'''
if not covimg_fn:
print("None image file to convert!")
exit()
outfile=""
for infile in covimg_fn:
f, e = os.path.splitext(infile)
if format.lower() == ("jpg", "jpeg"):
outfile = f + ".jpg"
print(outfile)
elif format.lower()=="gif":
outfile = f + ".gif"
print(outfile)
elif format.lower() == "png":
outfile = f + ".png"
print(outfile)
elif format.lower()=="bmp":
outfile = f + ".bmp"
print(outfile)
elif format.lower() == "tiff":
outfile = f + ".tiff"
print(outfile)
else:
print("Usage:Command <jpg|gif|bmp|png> filename1,filename2 ... ...")
exit()
if infile != outfile:
try:
Image.open(infile).save(outfile)
except IOError:
print("cannot convert:", infile)
if name == '__main__':
#change value you want
#"jpg,gif,tiff,bmp,png"
covimg_format=“jpg”
#images path of list or str
covimg_fn=[1.gif,2,gif,3.gif,4.tiff]
conv_img(covimg_fn,covimg_format)
'''
本作品采用 知识共享署名-相同方式共享 4.0 国际许可协议 进行许可。