admin管理员组

文章数量:1538129

PNG 创建于 1995 年,是用于在网络上传输图像的 GIF 格式的免费替代品。因为PNG没专利,所以编辑和查看PNG也不需要许可。PNG图像在压缩时不会丢失任何数据,编码、解码方式一样。与JPEG 文件等有损选项相比,这是一个很大的优势。

所以,要想把其它格式的图片转换为PNG格式是很方便的。除了一种情况,那就是图片比较多的时候。这时需要一些工具来帮助我们批量转换。很多解决方案都需要安装什么软件,下面这种,额……也需要安装脚本解释器,除此之外还得安装一个包:

pip install pillow

然后编写和执行脚本:

from multiprocessing import Pool
import os
import re
from PIL import Image


def save_single(
    root: str, source_filename: str, suffix: str, target_path: str, target_suffix: str='png'
):
    try:
        img = Image.open(os.path.join(root, source_filename+suffix))
        img = img.convert('RGB')
        img.save(os.path.join(target_path, f'

本文标签: 图片格式批量转换Python