dotfiles

Configuration for the software I use.
git clone https://git.sr.ht/~jbauer/dotfiles
Log | Files | Refs | README | LICENSE

commit 6ea121be0a9cd155d5de5194d94eb53e4e531d31
parent 77e39a6c0ee4c5e3d95f75f21f1cc9d30ea32232
Author: Jake Bauer <jbauer@paritybit.ca>
Date:   Mon,  7 Jun 2021 21:13:19 -0400

Add script to easily optimize images

Diffstat:
A.local/bin/optimizeimg | 38++++++++++++++++++++++++++++++++++++++
1 file changed, 38 insertions(+), 0 deletions(-)

diff --git a/.local/bin/optimizeimg b/.local/bin/optimizeimg @@ -0,0 +1,38 @@ +#!/bin/sh + +optimizejpg() +{ + convert \ + -sampling-factor 4:2:0 \ + -strip -quality 85 \ + -interlace JPEG \ + -colorspace RGB \ + "$file" \ + "$filename"-optimized.jpg + exiftool -all= "$filename"-optimized.jpg +} + +optimizepng() +{ + if [ ! -x $(command -v optipng) ]; then + echo "Optimizing PNGs requires the optipng program." + exit 1 + fi + optipng -out "$filename"-optimized.png "$file" + exiftool -all= "$filename"-optimized.png +} + +for file in "$@"; do + if [ -f "$file" ]; then + case "$file" in + *.jpg) filename=$(basename "$file" .jpg); optimizejpg ;; + *.jpeg) filename=$(basename "$file" .jpeg); optimizejpg ;; + *.png) filename=$(basename "$file" .png); optimizepng ;; + *) + filename=$(basename "$file" .png) + echo "The provided file is not a JPG or PNG, it will be converted to a PNG and optimized with optipng." + optimizepng + ;; + esac + fi +done