目录
一、安装 PIL
pip install Pillow
二、将PPM格式转为PNG格式
Python 代码:
# -*- coding:utf-8 -*-
from PIL import Image
import sys
def convert(filename):
im = Image.open(filename) # open ppm file
newname = filename[:-4] + '.png'# new name for png file
im.save(newname) # save picture to new file
if "__main__" == __name__:
filename= sys.argv[1]
convert(filename)
执行:
python ppm2png.py ppm-file.ppm