Skip to content

Instantly share code, notes, and snippets.

@mheland
Last active January 28, 2019 12:29
Show Gist options
  • Save mheland/032a4a619e20d8eddad80f237e3b49ee to your computer and use it in GitHub Desktop.
Save mheland/032a4a619e20d8eddad80f237e3b49ee to your computer and use it in GitHub Desktop.
Shell script to optimize PNG and JPEG from XFCE - Thunar
#!/bin/bash
for f in $@ #can be list of files
do
imagename=$(echo "$f" | cut -f 1 -d '.')
imagetype=$(echo "$f" | cut -f 2 -d '.')
outfile=$imagename"-web."$imagetype
if [ "$imagetype" = "png" ]
then #it's a PNG
gm convert $f -resize 1200 -enhance +profile "*" $outfile
pngquant $outfile
notify-send "Created optimized PNG image"
else [ "$imagetype" = "jpg" ] || [ "$imagetype" = "jpeg" ] #it's an JPEG
gm convert $f -resize 1200 -enhance -quality 70 +profile "*" $outfile
jpegoptim $outfile
notify-send "Created Optimized JPEG image"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment