Full Stack Software Developer

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

Leave a comment

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