插件安装
MoviePy==1.0.3
Pillow==9.0.1
# -*- coding: utf-8 -*-
# @Project :fileidentify
# @Date : 2022/4/1 14:35
# version: Python 3.8.*
# @File : ImageRead.py
import os
import sys
from PIL import Image
import moviepy.editor as mp
def webp2jpg(filepath):
im = Image.open(filepath)
newpath = filepath + '.jpg'
if im.mode == "RGBA":
im.load() # required for png.split()
background = Image.new("RGB", im.size, (255, 255, 255))
background.paste(im, mask=im.split()[3])
background.save(newpath)
else:
newpath = filepath + '.jpg'
im.save(newpath)
def GifToMp4(filepath):
clip = mp.VideoFileClip(filepath)
newpath = filepath + '.mp4'
clip.write_videofile(newpath)
def tiff(filepath):
(path, filename) = os.path.split(filepath)
image = Image.open(filepath) # 打开tiff图像
# 更改图像后缀为.jpg,并保证与原图像同名
distImagePath = os.path.join(path, filename[:-4] + '.jpg')
image.save(distImagePath) # 保存jpg图像
print(distImagePath)
网友评论