reconstruct
This commit is contained in:
parent
b21b25f376
commit
8697b83dc0
@ -1,12 +1,6 @@
|
||||
import asyncio
|
||||
import threading
|
||||
from time import sleep
|
||||
from typing import Any
|
||||
from PIL import Image
|
||||
import os
|
||||
import PySimpleGUI as sg
|
||||
|
||||
import webp_to_png
|
||||
from tools import convert_webp_to_png
|
||||
|
||||
layout = [
|
||||
[sg.Text("请选择webp文件夹:"),sg.Text("未选择文件夹"),sg.FolderBrowse("点击选择文件夹",key="input_folder")],
|
||||
@ -18,33 +12,6 @@ layout = [
|
||||
window = sg.Window("批量webp格式转化为png格式 -by Zengtudor",layout,size=(800,400),resizable=True)
|
||||
bar = window["bar"]
|
||||
|
||||
def convert_webp_to_png(webp_dir, png_dir):
|
||||
# 获取目录中以.webp结尾的文件列表
|
||||
webp_files = [f for f in os.listdir(webp_dir) if f.endswith('.webp')]
|
||||
# 获取文件总数
|
||||
nums = len(webp_files)
|
||||
# 初始化进度条计数器
|
||||
times = 0
|
||||
|
||||
# 遍历所有webp文件
|
||||
for file_name in webp_files:
|
||||
# 构建webp文件的路径
|
||||
webp_file_path = os.path.join(webp_dir, file_name)
|
||||
# 构建输出的png文件路径
|
||||
png_file_path = os.path.join(png_dir, os.path.splitext(file_name)[0] + '.png')
|
||||
|
||||
# 打开webp文件并保存为png
|
||||
with Image.open(webp_file_path) as img:
|
||||
img.save(png_file_path, 'PNG')
|
||||
|
||||
# 更新进度条
|
||||
times += 1
|
||||
progress = int(times/nums*100)
|
||||
window.write_event_value("bar",{"current_count":progress} )
|
||||
print("Conversion completed.")
|
||||
|
||||
|
||||
|
||||
def main():
|
||||
while True:
|
||||
ret = window.read()
|
||||
@ -54,16 +21,19 @@ def main():
|
||||
if event == sg.WIN_CLOSED : break
|
||||
elif event == "ok":
|
||||
# window.write_event_value("bar", {"current_count":50})
|
||||
print(value["input_folder"] and value["output_folder"])
|
||||
print(value["input_folder"] and value["output_folder"],"bool")
|
||||
if value["input_folder"] and value["output_folder"] :
|
||||
print("start")
|
||||
# convert_webp_to_png(value["input_folder"],value["output_folder"])
|
||||
threading.Thread(target=convert_webp_to_png,args=[value["input_folder"],value["output_folder"]],daemon=True).start()
|
||||
threading.Thread(target=convert_webp_to_png,
|
||||
args=[value["input_folder"], value["output_folder"], window]
|
||||
,daemon=True
|
||||
).start()
|
||||
else : sg.popup("你还没有选择路径!")
|
||||
elif event == "bar":
|
||||
print("freshing bar")
|
||||
bar.update(current_count=value["bar"]["current_count"])
|
||||
window.refresh()
|
||||
# window.refresh()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
26
webp_to_png/tools.py
Normal file
26
webp_to_png/tools.py
Normal file
@ -0,0 +1,26 @@
|
||||
import os
|
||||
from PIL import Image
|
||||
def convert_webp_to_png(webp_dir:str, png_dir:str,window)->None:
|
||||
# 获取目录中以.webp结尾的文件列表
|
||||
webp_files = [f for f in os.listdir(webp_dir) if f.endswith('.webp')]
|
||||
# 获取文件总数
|
||||
nums = len(webp_files)
|
||||
# 初始化进度条计数器
|
||||
times = 0
|
||||
|
||||
# 遍历所有webp文件
|
||||
for file_name in webp_files:
|
||||
# 构建webp文件的路径
|
||||
webp_file_path = os.path.join(webp_dir, file_name)
|
||||
# 构建输出的png文件路径
|
||||
png_file_path = os.path.join(png_dir, os.path.splitext(file_name)[0] + '.png')
|
||||
|
||||
# 打开webp文件并保存为png
|
||||
with Image.open(webp_file_path) as img:
|
||||
img.save(png_file_path, 'PNG')
|
||||
|
||||
# 更新进度条
|
||||
times += 1
|
||||
progress = int(times/nums*100)
|
||||
window.write_event_value("bar",{"current_count":progress} )
|
||||
print("Conversion completed.")
|
Loading…
Reference in New Issue
Block a user