Python 实现图像多种格式批量转换:.tiff,.jpg,.png 您所在的位置:网站首页 jpeg转jpg在线 Python 实现图像多种格式批量转换:.tiff,.jpg,.png

Python 实现图像多种格式批量转换:.tiff,.jpg,.png

2023-03-24 17:37| 来源: 网络整理| 查看: 265

第一次写博客,遇到了图像格式转换作个小记录,希望各位大佬指点~~

# 以tiff转jpg为例,其他格式同理, # 代码中路径更改为自己图像存放路径即可 from PIL import Image import os imagesDirectory=r"G:\tiffImages" # tiff图片所在文件夹路径 distDirectory = os.path.dirname(imagesDirectory)# 保证tiff图像文件夹与jpg图像文件夹在同一目录下 distDirectory = os.path.join(distDirectory, "jpgImages")# 要存放jpg格式的文件夹路径 for imageName in os.listdir(imagesDirectory): imagePath = os.path.join(imagesDirectory, imageName) image = Image.open(imagePath)# 打开tiff图像 distImagePath = os.path.join(distDirectory, imageName[:-5]+'.jpg')# 更改图像后缀为.jpg,并保证与原图像同名 image.save(distImagePath)# 保存jpg图像


【本文地址】

公司简介

联系我们

今日新闻

    推荐新闻

    专题文章
      CopyRight 2018-2019 实验室设备网 版权所有