python-image图片库使用

使用 python 处理 png 转 jpg 压缩 等图片处理,不过转出来的质量不太行,纯属娱乐


  1. 下载 Pillow-2.7.0-cp27-none-win_amd64.whl

    https://pypi.python.org/pypi/Pillow/2.7.0

  2. 安装

    1
    2
    3
    4
    5
    C:\Users\Administrator\Desktop>pip install Pillow-2.7.0-cp27-none-win_amd64.whl
    Unpacking c:\users\administrator\desktop\pillow-2.7.0-cp27-none-win_amd64.whl
    Installing collected packages: Pillow
    Successfully installed Pillow
    Cleaning up...
  3. 使用

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    def main():
    srcFile = "C:\\Users\\Administrator\\Desktop\\webp\\city_bailementex_01.png"
    srcFile.replace("\\", "/")
    dstFile = "C:\\Users\\Administrator\\Desktop\\webp\\city_bailementex_222.jpg"
    dstFile.replace("\\", "/")
    print("--- png2jpg begin")
    with Image.open(srcFile) as im:
    rgb_im = im.convert('RGB')
    rgb_im.save(dstFile, quality=80, format="jpeg")
    os.system("pause")

参考