You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

95 lines
2.6 KiB

#!/bin/bash
##This creates a red to blue divergent colorbar with specified label and bounds.
####
#Help
####
Help(){
echo "This creates a colorbar image file with specified boundaries and tag"
echo
echo "Syntax: colorbar [-h|-o outfile|-x width|-y height] caption lobd hibd"
echo "options:"
echo "-h: print this help"
echo "-o: Specify file to write to"
echo "-x: Specify width of colorbar image. Cannot be used with -y"
echo "-y: Specify height of colorbar image. Cannot be used with -x"
echo "caption: Caption for the colorbar"
echo "lobd: Lower bound of the color bar"
echo "hibd: Upper bound of the color bar"
}
outfile='colorbar.png'
declare -a args
argnum=0
x=0
y=0
while [ $# -gt 0 ]; do
unset OPTIND
unset OPTARG
#Parse Flags
while getopts ':ho:x:y:' options; do
case $options in
h)
Help
break;;
o)
outfile="$OPTARG";;
x)
x="$OPTARG"
if [ $y -ne 0 ]; then
echo "Cannot use both -x and -y options"
break
fi
;;
y)
y="$OPTARG"
if [ $x -ne 0 ]; then
echo "Cannot use both -x and -y options"
break
fi
;;
?)
esac
done
shift $((OPTIND-1))
args+=("$1")
(( argnum++ ))
shift
done
#Now pull out the required arguments
if [ "$args" = "" ]; then
Help
elif [ $argnum -ne 3 ]; then
echo "colorbar requires three positional arguments, you have supplied $argnum. Please view help"
echo ${args[0]} ${args[1]}
else
msg="${args[0]}"
lobd="${args[1]}"
hibd="${args[2]}"
#First copy colorbar file to current directory
cp ~/typesetting/figure_templates/colorbar.png $outfile
#Now create lower and upper labels
convert -background " #FFF " -fill black -font Helvetica -size x196 label:"$lobd" tmp1.png
convert -background " #FFF " -fill black -font Helvetica -size x196 label:"$hibd" tmp2.png
convert +append -gravity center tmp1.png $outfile tmp2.png $outfile
#Now create caption for image
convert -background " #FFF " -fill black -font Helvetica -size x196 label:"$msg" tmp.png
convert -append -gravity center tmp.png $outfile $outfile
#Final step is resizing
if [ $x -gt 0 ]; then
convert -scale "$x"x $outfile $outfile
fi
if [ $y -gt 0 ]; then
convert -scale x"$y" $outfile $outfile
fi
rm tmp.png tmp1.png tmp2.png
fi