When I upload images for my gemlog, I like them to be well-compressed with a maximum dimension of 800 pixels on the long side.
Also, I like all the identifying EXIF information (including the location) to be stripped.
So I wrote a shell script to do the dirty work, with a dependency on ImageMagick.
ImageMagick's website
Here are some examples:
stripexif infile.jpg outfile.jpg # Quality 75%, 800 px max
stripexif -q 90 infile.jpg outfile.jpg # Quality 90%, 800 px max
stripexif -d 500 infile.jpg outfile.jpg # Quality 75%, 500 px max
stripexif -q 70 -d 500 infile.jpg outfile.jpg # 70%, 500 px max
And here's the source. Note that if you have ImageMagick installed and the `magick` command isn't found, change it to `convert` (which is now deprecated).
#!/bin/sh
SCRIPT=$(basename $0)
usage_exit() {
printf "usage: %s [-q quality_pct] [-d max_dim] infile outfile\n" "$SCRIPT" 1>&2
exit 1
}
quality=""
max_dim=""
infile=""
outfile=""
while [ $# -gt 0 ]; do
case "$1" in
"-q")
shift
quality=$1
;;
"-d")
shift
max_dim=$1
;;
"-h"|"--help")
usage_exit
;;
*)
if [ -z "$infile" ]; then
infile="$1"
elif [ -z "$outfile" ]; then
outfile="$1"
else
usage_exit
fi
;;
esac
shift
done
if [ -z "$infile" -o -z "$outfile" ]; then
usage_exit
fi
if [ -z "$quality" ]; then
quality=75
fi
if [ -z "$max_dim" ]; then
max_dim=800
fi
quality_cl="-quality $quality%"
max_dim_cl="-resize ${max_dim}x${max_dim}\\>"
magick $infile -strip $quality_cl $max_dim_cl $outfile
Don't forget to `chmod 700 stripexif` and put it somewhere in your `PATH`. As a side note, I personally use the directory `~/.local/bin` for things like that.
Happy scripting!
───────────
Comments? Mail beej@beej.us.
Back to Beej's Gemlog
Back to Beej's Place