1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
import os import tkinter from threading import Thread from tkinter import filedialog from tkinter import Tk from PIL import Image
import pyheif
class HeicToJpg: """heic转jpg"""
def __init__(self): self.window = Tk() self.window.iconbitmap(r'F:\projects\guistudy\favicon.ico') self.window.geometry("510x250+750+200") self.window.resizable(width=False, height=False) self.window.title("HEIC转换JPG ——Author by 托小尼") self.strResult = tkinter.StringVar() self.btnPath = tkinter.Button(self.window, text='选择并转换', width=70, command=self.path_call_back) self.txtResult = tkinter.Text(self.window, width=70, height=15) self.txtResult.grid(row=1, column=0, padx=5, pady=5) self.txtResult.insert(tkinter.END, '转换任务列表……\n') self.btnPath.grid(row=2, column=0, padx=5, pady=5)
self.window.mainloop()
def heic_to_jpg(self, file): """heic转jpg""" save_dir = os.path.dirname(file) jpg_path = os.path.join(save_dir, '%s.jpg' % os.path.splitext(os.path.basename(file))[0]) heic_path = pyheif.read(file) img_bytes = Image.frombytes(mode=heic_path.mode, size=heic_path.size, data=heic_path.data) img_bytes.save(jpg_path, format='jpeg') self.txtResult.insert(tkinter.END, '【%s】转换完成\n' % file) self.txtResult.update() self.txtResult.see(tkinter.END)
def path_call_back(self): """读取要转换的文件""" file_paths = filedialog.askopenfilenames(title='请选择您要转换的HEIC文件(*可多选)', filetypes=[('HEIC文件', '*.heic'), ]) if file_paths: self.txtResult.delete(0.0, tkinter.END) self.txtResult.update() for file in file_paths: t = Thread(target=self.heic_to_jpg, args=(file,)) t.start()
if __name__ == '__main__': HeicToJpg()
|