def PnmToPng(pnmstring, reporterror = Utils.Error):
'''Convert a pnm file into a png file by piping through "pnmtopng".
"pnmstring" can either be a string or a list of strings. Accordingly,
one png in a string or a list of pngs in strings is returned.'''
if type(pnmstring) == types.ListType:
res = []
for p in pnmstring:
res.append(PnmToPng(p,reporterror))
return res
if type(pnmstring) != types.StringType:
return pnmstring
try:
inp,out = os.popen2('pnmtopng -compression 9 -background white '+
'-transparent white', bufsize=len(pnmstring)+1024)
inp.write(pnmstring)
inp.close()
res = out.read()
out.close()
except:
msg = 'Problems during call to "pnmtopng".'
reporterror(msg)
raise Utils.UtilsError, msg
return res
评论列表
文章目录