#!/bin/bash # copyright © 2008,2009 by # Thomas Arend ("Byggvir of Barley", http://www.byggvir.de). # Translated to bash by David Joyner http://www.ipernity.com/user/wdj # Requires imagemagick commands to be in your path # # Call this using the following syntax: # # calendar | sh # # where is in {1, 2, ..., 12} and # is a jpg, png, or gif file. The file # name outputed by this script has the form ip-. # The days of the month are superimposed on the bottom of the # picture. # ############################################################## [ $# -lt 3 ] && echo "usage $0 YEAR MONTH PICTURE" && exit 1 YEAR=${1} MONTH=${2} PICTURE=${3} # Get width and height of the picture W=`identify -format "%w" "${PICTURE}"` H=`identify -format "%h" "${PICTURE}"` # Define the number of days in a month DINM=(31 28 31 30 31 30 31 31 30 31 30 31) if [ $((YEAR % 4)) -eq 0 ]; then DINM[1]=29 if [ { ${{YEAR % 100}} -eq 0 } -a { ${{YEAR % 400}} -ne 0 } ]; then DINM[1]=28 fi fi # Define the days of the week [English version] # Modify the data below **and** the WDAY case below for # other languages. NOFD=(M T W Th F Sa Su) NOFM=(January February March April May June July August September October November December) PREFIX="ip" FONT="Andy MT" PTSIZE=$(((W>H?H:W)/40)) SIGN=" " # Uncomment the line below for a copyright notice. #SIGN="© 2008,2009 by XYZ" ## <-- replace "XYZ" by YOUR name here echo -e "convert \\" echo -e "-gravity North \\" echo -e "-pointsize 128 -family \"$FONT\" \\" echo -e "-fill Black -draw 'text 36,12 \"${NOFM[$((MONTH-1))]} $YEAR\"' \\" echo -e "-fill Lightgrey -draw 'text 31,7 \"${NOFM[$((MONTH-1))]} $YEAR\"' \\" echo -e "-gravity SouthEast \\" echo -e "-pointsize 16 -family \"$FONT\" \\" echo -e "-fill Black -draw 'text 32,8 \"$SIGN\"' \\" echo -e "-fill Lightgrey -draw 'text 31,7 \"$SIGN\"' \\" echo -e "-gravity NorthWest \\" echo -e "-pointsize $PTSIZE -family \"$FONT\" \\" DEFCOL1=Red DEFCOL2=MediumVioletRed DEFCOL3=Black COLOR=$DEFCOL3 COLSHADOW=Lightgrey for (( d=1 ; d <= DINM[MONTH-1] ; d++ )); do X=$((W*(2*d-1)/2/(DINM[MONTH-1]+1))) Y=$((H-3*PTSIZE-5)) WDAY=${NOFD[`date +%w -d "$YEAR-$MONTH-$d"`]} case "$WDAY" in Su) COLOR=$DEFCOL1 ;; # <-- Su="Sunday" Sa) COLOR=$DEFCOL2 ;; # <-- Sa="Saturday" * ) COLOR=$DEFCOL3 ;; # <-- other days of the week esac echo "-fill $COLSHADOW -draw 'text $X,$Y \"$WDAY\"' \\" echo "-fill $COLOR -draw " "'text $(($X-1)),$(($Y-1)) \"$WDAY\"' \\" Y=$((H-2*PTSIZE)) echo "-fill $COLSHADOW -draw 'text $X,$Y \"$d\"' \\" echo "-fill $COLOR -draw 'text $(($X-1)),$(($Y-1)) \"$d\"' \\" done #echo "\"${PICTURE}\" \"${PICTURE%/*}/${PREFIX}-${PICTURE##*/}\" " if [ ! "${PICTURE%/*}" = "${PICTURE##*/}" ]; then echo "\"${PICTURE}\" \"${PICTURE%/*}/${PREFIX}-${PICTURE##*/}\" " else echo "\"${PICTURE}\" \"${PREFIX}-${PICTURE##*/}\" " fi