-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcwebp.py
More file actions
executable file
·27 lines (23 loc) · 790 Bytes
/
cwebp.py
File metadata and controls
executable file
·27 lines (23 loc) · 790 Bytes
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
"""Module: Covert .png to .webp"""
import os
import sys
def convert_webp(path = 'content'):
"""Converts .png to .webp using cwebp, the path of the directory as an argument"""
for root, dirs, files in os.walk(path):
for file in files:
if file.endswith('.png'):
fullpath = os.path.join(root, file)
os.system('cwebp -q 80 ' + fullpath + ' -o ' + fullpath[:-4] + '.webp')
os.system('rm ' + fullpath)
if __name__ == '__main__':
# Get the directory path from the CLI
if len(sys.argv) > 1:
path = sys.argv[1]
convert_webp(path)
else:
convert_webp()
# Sample Input in CLI:
# python3 cwebp.py content/blogs/training/modern-devops/img