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实现自动扫雷,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友可以参考下 自动扫雷一般分为两种,一种是读取内...

记录Django开发心得

概念层面 概括 Django是属于MVC的Web框架。 Model:负责与数据库打交道 View:负责获取或者增强从Models得到的数据 Controller:这是Django本身 P...

基于python及pytorch中乘法的使用详解

numpy中的乘法 A = np.array([[1, 2, 3], [2, 3, 4]]) B = np.array([[1, 0, 1], [2, 1, -1]]) C = np...

python输入多行字符串的方法总结

Python中输入多行字符串: 方法一:使用三引号 >>> str1 = '''Le vent se lève, il faut tenter de vivre....

Python调用SQLPlus来操作和解析Oracle数据库的方法

先来看一个简单的利用python调用sqlplus来输出结果的例子: import os import sys from subprocess import Popen, PIPE...