Skip to content

Instantly share code, notes, and snippets.

@rkhapov
Created December 19, 2017 15:45
Show Gist options
  • Save rkhapov/9c0049fc86246751e590bf70b2150e76 to your computer and use it in GitHub Desktop.
Save rkhapov/9c0049fc86246751e590bf70b2150e76 to your computer and use it in GitHub Desktop.
add text task
#!/bin/bash
if [ "$1" = "-h" -o "$1" = "--help" ]; then
echo "This is script for adding text at the rigth corner"
echo "Usage: ./addtext.sh <input_directory> <text> <output_directory>"
exit 0
fi
if ! [ "$1" ] || ! [ "$2" ] || ! [ "$3" ]; then
echo "Error: expected parameters (see -h or --help for more)"
exit 1
fi
if ! [ -d "$1" ]; then
echo "Expected directory at first parameter"
exit 1
fi
if ! [ -d "$3" ]; then
mkdir "$3"
if [ $? -ne 0 ]; then
echo Cannot create a directory "$3"
exit 1
fi
fi
for file in "$1"/*
do
if [ ${file##*.} != "jpg" -a ${file##*.} != "png" ]; then
continue
fi
fname=$(basename "${file}")
name="${fname%.*}_annotated.${file##*.}"
convert "$file" -font DejaVu-Sans -pointsize 50 -gravity Southeast -annotate +0+0 "$2" "$3/$name" 2>/dev/null
if [ $? -ne 0 ]; then
echo Cannot convert file $name
exit 1
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment