-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebToPng.py
138 lines (111 loc) · 4.43 KB
/
WebToPng.py
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from PIL import Image
import os
PngFile = []
WebpFile = []
def main():
for file in os.listdir():
if file.endswith('.png'):# png
PngFile.append(file)
if file.endswith('.webp'):# webp
WebpFile.append(file)
def PngToWebp():
main()
# 'webptopng' klasörünün varlığını kontrol et ve gerekirse oluştur
output_folder = 'webptopng'
if not os.path.exists(output_folder):
os.makedirs(output_folder)
for file in PngFile:
# png dosyasını aç
im = Image.open(file)
# Çıktı dosyasının adını belirleyin (aynı dosya adıyla .webp uzantısı)
image_webp = f"{file.split('.')[0]}.webp"
# Çıktı dosyasını 'webptopng' klasörüne kaydet
output_path = os.path.join(output_folder, image_webp)
im.save(output_path, format="webp", lossless=True)
# Listeyi temizleyin
PngFile.clear()
WebpFile.clear()
def WebpToPng():
main()
# 'webtopng' klasörünün varlığını kontrol et ve gerekirse oluştur
output_folder = 'webtopng'
if not os.path.exists(output_folder):
os.makedirs(output_folder)
for file in WebpFile:
# webp dosyasını aç
im = Image.open(file)
# Çıktı dosyasının adını belirleyin (aynı dosya adıyla .png uzantısı)
image_png = f"{file.split('.')[0]}.png"
# Çıktı dosyasını 'webtopng' klasörüne kaydet
output_path = os.path.join(output_folder, image_png)
im.save(output_path, format="png", lossless=True)
# Listeyi temizleyin
PngFile.clear()
WebpFile.clear()
def PngToWebpAll():
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith(".png"):
print(file)
source_file = os.path.join(root, file)
webp_filepath = os.path.join(root, file)
target_file = source_file[:-5] + ".webp"
image = Image.open(source_file)
image.save(target_file)
os.remove(webp_filepath)
def WebpToPngAll():
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith(".webp"):
print(file)
source_file = os.path.join(root, file)
webp_filepath = os.path.join(root, file)
target_file = source_file[:-5] + ".png"
image = Image.open(source_file)
image.save(target_file)
os.remove(webp_filepath)
def PngToJpgAll():
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith(".png"):
print(file)
source_file = os.path.join(root, file)
webp_filepath = os.path.join(root, file)
target_file = source_file[:-5] + ".jpg"
image = Image.open(source_file)
image.save(target_file)
os.remove(webp_filepath)
def JpgToPngAll():
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith(".jpg"):
print(file)
source_file = os.path.join(root, file)
webp_filepath = os.path.join(root, file)
target_file = source_file[:-5] + ".png"
image = Image.open(source_file)
image.save(target_file)
os.remove(webp_filepath)
def WebpToJpgAll():
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith(".webp"):
print(file)
source_file = os.path.join(root, file)
webp_filepath = os.path.join(root, file)
target_file = source_file[:-5] + ".jpg"
image = Image.open(source_file)
image.save(target_file)
os.remove(webp_filepath)
def JpgToWebpAll():
for root, dirs, files in os.walk('.'):
for file in files:
if file.endswith(".jpg"):
print(file)
source_file = os.path.join(root, file)
webp_filepath = os.path.join(root, file)
target_file = source_file[:-5] + ".webp"
image = Image.open(source_file)
image.save(target_file)
os.remove(webp_filepath)
WebpToPng()