This commit is contained in:
ZtRXR 2024-05-04 00:27:19 +08:00
parent 1de3b65e41
commit cf01b0b7e9
5 changed files with 93 additions and 161 deletions

165
.gitignore vendored
View File

@ -1,162 +1,5 @@
# ---> Python
# Byte-compiled / optimized / DLL files
/dist
/poetry.lock
/build
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/
cover/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
.pybuilder/
target/
# Jupyter Notebook
.ipynb_checkpoints
# IPython
profile_default/
ipython_config.py
# pyenv
# For a library or package, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# .python-version
# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock
# poetry
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
# This is especially recommended for binary packages to ensure reproducibility, and is more
# commonly ignored for libraries.
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
#poetry.lock
# pdm
# Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
#pdm.lock
# pdm stores project-wide configurations in .pdm.toml, but it is recommended to not include it
# in version control.
# https://pdm.fming.dev/#use-with-ide
.pdm.toml
# PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
__pypackages__/
# Celery stuff
celerybeat-schedule
celerybeat.pid
# SageMath parsed files
*.sage.py
# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/
# Spyder project settings
.spyderproject
.spyproject
# Rope project settings
.ropeproject
# mkdocs documentation
/site
# mypy
.mypy_cache/
.dmypy.json
dmypy.json
# Pyre type checker
.pyre/
# pytype static type analyzer
.pytype/
# Cython debug symbols
cython_debug/
# PyCharm
# JetBrains specific template is maintained in a separate JetBrains.gitignore that can
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
/.vscode

19
pyproject.toml Normal file
View File

@ -0,0 +1,19 @@
[tool.poetry-pyinstaller-plugin.scripts]
webp_to_png = { source = "webp_to_png/__main__.pyw", type = "onedir", bundle = false }
[tool.poetry]
name = "webp-to-png"
version = "0.1.0"
description = ""
authors = ["ZtRXR <Zengtudor@outlook.com>"]
readme = "README.md"
[tool.poetry.dependencies]
python = "^3.12"
pillow = "^10.3.0"
pysimplegui = "4.59"
[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

0
tests/__init__.py Normal file
View File

0
webp_to_png/__init__.py Normal file
View File

70
webp_to_png/__main__.pyw Normal file
View File

@ -0,0 +1,70 @@
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
layout = [
[sg.Text("请选择webp文件夹:"),sg.Text("未选择文件夹"),sg.FolderBrowse("点击选择文件夹",key="input_folder")],
[sg.Text("请选择png文件夹:"),sg.Text("未选择文件夹"),sg.FolderBrowse("点击选择文件夹",key="output_folder")],
[sg.Button("开始执行",key="ok")],
[sg.Text("完成进度:"),sg.ProgressBar(max_value=100,key="bar",size=(50,20),)]
]
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()
if ret:
event , value = ret
print(event,value)
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"])
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()
else : sg.popup("你还没有选择路径!")
elif event == "bar":
print("freshing bar")
bar.update(current_count=value["bar"]["current_count"])
window.refresh()
if __name__ == "__main__":
main()