16 lines
675 B
Python
16 lines
675 B
Python
|
import os
|
||
|
import sys
|
||
|
from PIL import Image
|
||
|
if __name__ == '__main__':
|
||
|
originalfiles = [f for f in os.listdir('original') if os.path.isfile(os.path.join('original', f))]
|
||
|
existingfiles = [f for f in os.listdir('webp') if os.path.isfile(os.path.join('webp', f))]
|
||
|
for f in originalfiles:
|
||
|
if f.split(".")[0] + '.webp' in existingfiles:
|
||
|
print("skipped: " + f)
|
||
|
continue
|
||
|
try:
|
||
|
im = Image.open('original/' + f).convert('RGB')
|
||
|
im.save('webp/' + f.split(".")[0] + '.webp', 'WEBP', quality=90)
|
||
|
print("optimized: " + f)
|
||
|
except OSError:
|
||
|
print("Falied to optimize the picture: " + f)
|