Skip to content

Instantly share code, notes, and snippets.

@jeremija
Created September 17, 2014 18:12
Show Gist options
  • Save jeremija/1a24c3aa1d51cec5ede7 to your computer and use it in GitHub Desktop.
Save jeremija/1a24c3aa1d51cec5ede7 to your computer and use it in GitHub Desktop.
Resize with watermark
#!/bin/bash
# author jsteiner
#
# Resizes an image and adds a watermark. To customize which watermark is added,
# edit the $WATERMARK variable below.
#
DIR=`dirname "$BASH_SOURCE"`
WATERMARK="$DIR/watermark.png"
SRC="$1"
DIM="$2"
DEST="$3"
DEST_FILE="$DEST/$1"
if [ $# -ne 3 ]; then
echo "invalid number of arguments supplied"
echo "usage: `basename $0` <source_file> <dimensions> <dest_dir>"
echo "where:"
echo " <source_file> is an image file"
echo " <dimensions> dimensions of new file, for example:"
echo " 1280x720, or 1280x, or 720x"
echo " <dest_dir> output dir in which a new directory"
echo " called 'resized/' will be created"
exit 1;
fi
if [ ! -f "$SRC" ]; then
echo "error: source file $1 does not exist"
exit 2
fi
if [ ! -d "$DEST" ]; then
echo "error: destination $DEST is not a directory"
exit 3
fi
if [ -f "$DEST_FILE" ]; then
echo "error: destination file $DEST_FILE already exists"
exit 4
fi
# first resize the file, then apply the watermark. miff:- makes piping available
convert "$SRC" -resize "$DIM" miff:- | composite -gravity southeast -geometry +10+10 "$WATERMARK" miff:- "$DEST_FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment