Last active
January 19, 2017 22:20
-
-
Save akhal3d96/c4fcbe54d2263096b54fb83cc1f464f1 to your computer and use it in GitHub Desktop.
A simple script to convert the grabage you collect through the internet (aka memes) and other unimportant images you have to lossy webp image which will save you some space. Past it into a directory and it will compress anything in it. It's very destructive use it wisely.
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/bash | |
BSIZE=$(du -Ss $PWD | awk '{print $1}') | |
function finish(){ | |
ASIZE=$(du -Ss $PWD | awk '{print $1}') | |
FSIZE=$((BSIZE-ASIZE)) | |
echo $(python -c "print($FSIZE/1000.0)")MB | |
} | |
trap finish EXIT | |
find $PWD -maxdepth 1 -size -1024k -iname "*.jpg" -or -iname "*.png" | xargs -I '{}' sh -c '(echo converting "{}" && cwebp "{}" -mt -q 80 -o "{}".webp 2> /dev/null || true) && rm "{}"' | |
#Remove -maxdepth 1 to make it recursive (NOT RECOMMENDED) | |
#This script assumes the average sizes of your unimportant image is less that 1MB you can alter that behavior through editing -size -1024k see man find |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment