def picon_post_processing(self, piconfilepath):
"""Check type of image received and convert to png
if necessary
"""
ext = ""
# get image type
try:
ext = imghdr.what(piconfilepath)
except Exception, e:
if DEBUG:
print(e)
return
# if image but not png convert to png
if (ext is not None) and (ext is not 'png'):
if DEBUG:
print('Converting Picon to png')
try:
Image.open(piconfilepath).save("{}.{}".format(piconfilepath, 'png'))
except Exception, e:
if DEBUG:
print(e)
return
try:
# remove non png file
os.remove(piconfilepath)
except Exception, e:
if DEBUG:
print(e)
return
else:
# rename to correct extension
try:
os.rename(piconfilepath, "{}.{}".format(piconfilepath, ext))
except Exception, e:
if DEBUG:
print(e)
pass
评论列表
文章目录