Skip to content

Instantly share code, notes, and snippets.

@travelbluff
Last active August 29, 2015 14:23
Show Gist options
  • Select an option

  • Save travelbluff/f45c309b7b4f90886a64 to your computer and use it in GitHub Desktop.

Select an option

Save travelbluff/f45c309b7b4f90886a64 to your computer and use it in GitHub Desktop.
Preparing images with GraphicsMagick

Resize

gm convert -strip -resize $RESIZE -define jpeg:preserve-settings $INPUT $TMPIMG

Watermark

gm convert -size $(gm identify -format %wx%h $TMPIMG) xc:none -pointsize 12 -font helvetica -gravity southeast -fill "#000" -draw "text 10,10 '$TEXT'" -fill "#fff" -draw "text 11,10 '$TEXT'" png:-

Magick

gm convert -strip -resize $RESIZE -define jpeg:preserve-settings $INPUT $TMPIMG && gm convert -size $(gm identify -format %wx%h $TMPIMG) xc:none -pointsize 12 -font helvetica -gravity southeast -fill "#000" -draw "text 10,10 '$TEXT'" -fill "#fff" -draw "text 11,10 '$TEXT'" png:- | gm composite -dissolve 50 -interlace Line -quality $QUALITY - $TMPIMG $OUTPUT
#!/usr/bin/env bash
if [ ! -x $(which gm) ]
then
echo "GraphicsMagick is required."
exit 1
fi
TMPDIR=$(mktemp -d)
OUTDIR=../output
[ -d $OUTDIR ] || mkdir $OUTDIR
for file in *
do
INPUT="$file"
TMPIMG="$TMPDIR/$INPUT"
_FILE="${INPUT//-/_}"
_FILE="${_FILE,,}"
_FILE="${_FILE//.jpeg/.jpg}"
OUTPUT="$OUTDIR/$_FILE"
gm convert -strip -resize $RESIZE -define jpeg:preserve-settings $INPUT $TMPIMG
gm convert -size $(gm identify -format %wx%h $TMPIMG) xc:none \
-pointsize 18 \
-font helvetica \
-gravity southeast \
-fill "#000" \
-draw "text 10,10 '$TEXT'" \
-fill "#fff" \
-draw "text 11,10 '$TEXT'" png:- | \
gm composite -dissolve 50 -interlace Line -quality $QUALITY - $TMPIMG $OUTPUT
done
rm -r $TMPDIR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment