吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 1391|回复: 42
收起左侧

[原创工具] 批量webp转png小工具.

[复制链接]
良心小小酥 发表于 2025-2-3 14:10
自己是做电商的,有时候保存下来的图片是webp格式的.
写了个小工具.能把目录内的webp格式的图片转化成png.
PddScreenShot_20250203140903.png


https://crk.lanzouu.com/iZdWG2mla0wd


Python代码一起附上.
[Python] 纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
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
import os
from PIL import Image
import tkinter as tk
from tkinter import filedialog, messagebox
 
def convert_webp_to_png(directory_path):
    converted_count = 0
    for root, dirs, files in os.walk(directory_path):
        for file in files:
            if file.endswith('.webp'):
                webp_path = os.path.join(root, file)
                png_path = os.path.splitext(webp_path)[0] + '.png'
                try:
                    image = Image.open(webp_path)
                    image.save(png_path, 'PNG')
                    os.remove(webp_path)
                    converted_count += 1
                except Exception as e:
                    messagebox.showerror("转换错误", f"文件'{file}'转换失败:{str(e)}")
 
    messagebox.showinfo("转换完成", f"成功转换 {converted_count} 个文件!")
 
def select_directory():
    directory = filedialog.askdirectory()
    if directory:
        directory_label.config(text=directory)
 
def convert_files():
    directory_path = directory_label.cget("text")
    if directory_path:
        convert_webp_to_png(directory_path)
 
# 创建主窗口
window = tk.Tk()
window.title("WebP转换PNG- - - -云时出品- -")
window.geometry("350x100")
 
# 创建选择目录按钮
select_button = tk.Button(window, text="选择目录", command=select_directory)
select_button.pack()
 
# 创建显示目录路径的标签
directory_label = tk.Label(window, text="")
directory_label.pack()
 
# 创建执行转换按钮
convert_button = tk.Button(window, text="执行转换", command=convert_files)
convert_button.pack()
 
# 显示窗口
window.mainloop()

免费评分

参与人数 6吾爱币 +12 热心值 +6 收起 理由
huiker231 + 1 + 1 用心讨论,共获提升!
LuckyClover + 1 + 1 用心讨论,共获提升!
waksy + 1 + 1 谢谢@Thanks!
bqi153 + 1 + 1 谢谢@Thanks!
JF300666 + 1 + 1 谢谢@Thanks!
风之暇想 + 7 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

aria1983 发表于 2025-2-6 08:38
要是可以拖拽就更方便了

点评

这个支持https://www.52pojie.cn/thread-1983678-1-1.html  发表于 2025-2-7 12:28
minminawl 发表于 2025-2-6 09:01
挺不错,之前发现好多图批量存下来就是webp格式,转换很麻烦。
Bjityw 发表于 2025-2-6 10:16
vkjia 发表于 2025-2-6 11:50
支持一下原创作品!
david4801 发表于 2025-2-6 12:57
突然不少网站的图片都是webp格式,这个转换方便多了。多谢大佬
luoyr 发表于 2025-2-6 19:52
感谢分享
simon6902 发表于 2025-2-6 22:20
支持原创,谢谢分享
fxd680126 发表于 2025-2-7 07:39
感谢分享!下载试试。
澧水 发表于 2025-2-7 08:01
谢谢方便的小工具。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-3-14 10:53

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表