Created
March 23, 2017 20:50
-
-
Save santi020k/1e1299d58e2a8d4e2d67c0c7cac00604 to your computer and use it in GitHub Desktop.
Optimizing images inside a folder in the console linux
This file contains hidden or 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
## Linux bash script | |
# Optimizing images inside a folder in the console linux (jpg and png) | |
## Dependencies | |
# Use Linux operating system | |
# install jpegoptim | |
# To install the program on Debian/Ubuntu: | |
# $ sudo apt-get install jpegoptim | |
# To install on Fedora/RedHat/Centos: | |
# $ sudo yum install jpegoptim | |
# Install optipng | |
# To install the program on Debian/Ubuntu is: | |
# $ sudo apt-get install optipng | |
# For Fedora/Centos/RedHat, execute: | |
# $ sudo yum install optipng | |
# How use | |
# Run in terminal | |
# sh compressImages.sh folderName | |
# Optional params (jpeg compression ratio) | |
# sh compressImages.sh folderName 80 | |
#Code | |
#!/bin/bash | |
#optimize_images | |
if [ -d $1 ]; | |
then | |
#echo "Yes, it does exist." | |
for image in $(find $1 -name "*.jpg" ); | |
do | |
#echo "$image" | |
jpegoptim --strip-all --all-progressive --max=90 "$image" | |
done | |
for image in $(find $1 -name "*.png" ); | |
do | |
optipng -o2 -strip all -clobber "$image" | |
done | |
else | |
echo "No, it does exist" | |
fi | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment