python bmp转换为jpg 并删除原图的方法

夏夜,天上缀满了闪闪发光的星星,像细碎的流沙铺成的银河斜躺在青色的天宇上。大地已经沉睡了。我任了性,纵容思念开成一片海,定格成回忆里抹不去的风景。太阳把大海映红了,好像得大海披上了一层红纱。

如下所示:

# coding:utf-8
import os

from PIL import Image


# bmp 转换为jpg
def bmpToJpg(file_path):
 for fileName in os.listdir(file_path):
  # print(fileName)
  newFileName = fileName[0:fileName.find("_")]+".jpg"
  print(newFileName)
  im = Image.open(file_path+"\\"+fileName)
  im.save(file_path+"\\"+newFileName)


# 删除原来的位图
def deleteImages(file_path, imageFormat):
 command = "del "+file_path+"\\*."+imageFormat
 os.system(command)


def main():
 file_path = "D:\\VideoPhotos"
 bmpToJpg(file_path)
 deleteImages(file_path, "bmp")


if __name__ == '__main__':
 main()

以上这篇python bmp转换为jpg 并删除原图的方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持。

您可能有感兴趣的文章
Python-时间转换为时间戳

使用Python将字符串转换为格式化的日期时间字符串

Python将主机名转换为IP地址的方法

详解将Python程序(.py)转换为Windows可执行文件(.exe)

python实现批量nii文件转换为png图像