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的条件锁与事件共享详解

1:事件机制共享队列: 利用消息机制在两个队列中,通过传递消息,实现可以控制的生产者消费者问题 要求:readthread读时,writethread不能写;writethread写...

Python PIL图片添加字体的例子

Python PIL图片添加字体的例子

效果 左边原图,右面添加字体后保存的图。 代码 # -*- coding: utf-8 -*- import PIL.Image as Image import PIL.Image...

Django获取应用下的所有models的例子

Django获取应用下的所有models from django.apps import apps apps.get_models() # 获取所有的models,包含Djang...

利用Python开发实现简单的记事本

利用Python开发实现简单的记事本

前言 本文的操作环境:ubuntu,Python2.7,采用的是Pycharm进行代码编辑,个人很喜欢它的代码自动补齐功能。 示例图 如上图,我们可以看到这个记事本主要分为三个模块:文...

通过python的matplotlib包将Tensorflow数据进行可视化的方法

通过python的matplotlib包将Tensorflow数据进行可视化的方法

使用matplotlib中的一些函数将tensorflow中的数据可视化,更加便于分析 import tensorflow as tf import numpy as np impo...