Batch compress image using google guetzli

You can use the following code written by me to run batch compression of images with google’s guetzli image compression tool. It creates a compressed folder and saves all the compressed images of the folder inside the folder. Note: Right now this only compresses image from the location that is given and not the sub-folders.

Usage:

Syntax: base [stcriptname] [relative folder location] [percentage]

Implementation: bash batch-compresssion . 84

#/usr/bin/bash

if [ ! -d "$1/compressed" ]; then
	mkdir "$1/compressed"
fi

for file in $1/*.png
do
  echo $file
  guetzli --quality $2 "$file" "$1/compressed/$file"
done

for file in $1/*.jpg
do
  echo $file
  guetzli --quality $2 "$file" "$1/compressed/$file"
done

for file in $1/*.jpeg
do
  echo $file
  guetzli --quality $2 "$file" "$1/compressed/$file"
done
Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.