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获取指定网页上所有超链接的方法

本文实例讲述了python获取指定网页上所有超链接的方法。分享给大家供大家参考。具体如下: 这段python代码通过urllib2抓取网页,然后通过简单的正则表达式分析网页上的全部url...

对Python3中的print函数以及与python2的对比分析

对Python3中的print函数以及与python2的对比分析

本文首先介绍在python3中print函数的应用,然后对比在pyhton2中的应用。(本文作者所用版本为3.6.0) 首先我们通过help(print)命令来查看print函数的相关信...

Python中请不要再用re.compile了

Python中请不要再用re.compile了

前言 如果大家在网上搜索Python 正则表达式,你将会看到大量的垃圾文章会这样写代码: import re pattern = re.compile('正则表达式') text...

python 实现敏感词过滤的方法

如下所示: #!/usr/bin/python2.6 # -*- coding: utf-8 -*- import time class Node(object): d...

Python数据结构与算法之使用队列解决小猫钓鱼问题

Python数据结构与算法之使用队列解决小猫钓鱼问题

本文实例讲述了Python数据结构与算法之使用队列解决小猫钓鱼问题。分享给大家供大家参考,具体如下: 按照《啊哈》里的思路实现这道题目,但是和结果不一样,我自己用一幅牌试了一下,发现是我...