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

yipeiwu_com5年前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学生信息管理系统(完整版)

本文是基于上一篇(python项目:学生信息管理系统(初版) )进行了完善,并添加了新的功能。 主要包括有: 完善部分:输入错误;无数据查询等异常错误 新的功能:文件的操作:文件的读写,...

基于python指定包的安装路径方法

通常python安装包都会被默认装在/usr/local/pythonx/lib/site-packages(linux),但是我们有时想自定义包的安装路径,比如自己项目的某个路径,这样...

Python Gitlab Api 使用方法

简述 公司使用gitlab 来托管代码,日常代码merge request 以及其他管理是交给测试,鉴于操作需经常打开网页,重复且繁琐,所以交给Python 管理。 官方文档 安装 pi...

python中for用来遍历range函数的方法

python中for用来遍历range函数的方法

栗子:计算斐波那契数列(任一个数都是前两个数之和的数字序列) Python2.7实现代码如下: <strong><span style="font-size:14p...

合并百度影音的离线数据( with python 2.3)

四种格式的解析: filelist slicelist download.cfg third_party_download.cfg 还是2个文件。替换之前版本即可。 初步测试正常,但时间...