Last active
January 24, 2022 05:30
-
-
Save dudor/979378c18dc07e7b599c737c6120bd9b to your computer and use it in GitHub Desktop.
CONVERT JPG , PNG TO WEBP
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import sys | |
import subprocess | |
import os | |
def cwebp(dir): | |
for item in os.listdir(dir): | |
file = os.path.join(dir,item) | |
if(os.path.isfile(file)): | |
ext =os.path.splitext(file) | |
if(os.path.getsize(file) > 100000 and (ext[1].lower()==".jpg" or ext[1].lower()==".png")): | |
#print(ext) | |
r=subprocess.call(["cwebp","-metadata","all","-q","90","-mt",file,"-o",file+".webp"]) | |
print(r) | |
os.remove(file) | |
if(os.path.isdir(file)): | |
print(file) | |
cwebp(file) | |
cwebp(".") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
cwebp_img(){ | |
for f in $1"/"*;do | |
#echo "$f" | |
#cwebp -q 90 "$f" -o "$f.webp" | |
if [ -d "$f" ] | |
then | |
#cwebp_img "$1/$f" | |
echo "$f" | |
cwebp_img "$f" | |
else | |
filesize=`ls -l "$f" | awk '{ print $5 }'` | |
if [ $filesize -gt 204800 ] | |
then | |
if [ "${f##*.}"x = "jpg"x ]||[ "${f##*.}"x = "png"x ]||[ "${f##*.}"x = "JPG"x ]||[ "${f##*.}"x = "PNG"x ];then | |
cwebp -mt -q 85 -metadata all "$f" -o "$f.webp" | |
#echo "$f.webp" | |
rm "$f" | |
fi | |
fi | |
fi | |
done | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment