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

yipeiwu_com6年前Python基础

如下所示:

# 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编程在flask中模拟进行Restful的CRUD操作

Python编程在flask中模拟进行Restful的CRUD操作

这篇文章中我们将通过对HelloWorld的message进行操作,介绍一下如何使用flask进行Restful的CRUD。 概要信息 事前准备:flask liumiaocn:f...

python 实现图片旋转 上下左右 180度旋转的示例

如下所示: #首先建好一个数据_ud文件夹 import PIL.Image as img import os path_old = "C:/Users/49691/Desktop/...

python中关于时间和日期函数的常用计算总结(time和datatime)

1.获取当前时间的两种方法: 复制代码 代码如下:import datetime,timenow = time.strftime("%Y-%m-%d %H:%M:%S")print no...

Python实现对PPT文件进行截图操作的方法

本文实例讲述了Python实现对PPT文件进行截图操作的方法。分享给大家供大家参考。具体分析如下: 下面的代码可以为powerpoint文件ppt进行截图,可以指定要截取的幻灯片页面,需...

wxPython框架类和面板类的使用实例

wxPython框架类和面板类的使用实例

本文实例讲述了wxPython框架类和面板类的使用方法,分享给大家供大家参考。具体分析如下: 实现代码如下: import wx class MyApp(wx.App):...