#!/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-7x7 | sh # # where is in {1, 2, ..., 12} and # is a jpg, png, or gif file. The file # name outputted by this script has the form ip-. # The days of the month are superimposed in a 7x7 square # in the lower left corner of the picture. # ############################################################## [ $# -lt 3 ] && echo "usage calender YEAR MONTH PICTURE" && exit 1 YEAR=${1} MONTH=${2} PICTURE=${3} DIR=${3%/*} # Get width and height of the picture W=`identify -format "%w" "${PICTURE}"` H=`identify -format "%h" "${PICTURE}"` #W=1280 #H=1024 DEFCOL1=Red DEFCOL2=MediumVioletRed DEFCOL3=Black COLOR=$DEFCOL3 SHADOW=Lightgrey # 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 "-size ${W}x${H} xc:none \\" echo -e "-gravity SouthEast \\" echo -e "-pointsize 16 -family \"$FONT\" \\" echo -e "-fill $SHADOW -draw 'text 32,8 \"$SIGN\"' \\" echo -e "-fill $COLOR -draw 'text 31,7 \"$SIGN\"' \\" echo -e "-gravity SouthWest \\" echo -e "-pointsize $((3*PTSIZE/2)) -family \"$FONT\" \\" X=$((W/64)) Y=$((8*(PTSIZE+5))) echo -e "-fill $SHADOW -draw 'text $X,$Y \"${NOFM[$((MONTH-1))]} $YEAR\"' \\" echo -e "-fill $COLOR -draw 'text $((X-1)),$((Y-1)) \"${NOFM[$((MONTH-1))]} $YEAR\"' \\" Y=$((7*(PTSIZE+5))) echo -e "-pointsize $PTSIZE -family \"$FONT\" \\" for (( d=0 ; d < 7 ; d++ )); do X=$((W*(2*d+1)/64)) WDAY=${NOFD[$d]} case "$WDAY" in Su) COLOR=$DEFCOL1 ;; # <-- Su="Sunday" Sa) COLOR=$DEFCOL2 ;; # <-- Sa="Saturday" * ) COLOR=$DEFCOL3 ;; # <-- other days of the week esac echo "-fill $SHADOW -draw 'text $X,$Y \"$WDAY\"' \\" echo "-fill $COLOR -draw " "'text $((X-1)),$((Y-1)) \"$WDAY\"' \\" done WDAY1=$(((`date +%w -d "$YEAR-$MONTH-1"`+6)%7)) for (( d=1 ; d <= DINM[MONTH-1] ; d++ )); do X=$((W*(2*((WDAY1+d-1)%7)+1)/64)) WDAY=${NOFD[$(((WDAY1+d-1) % 7))]} case "$WDAY" in Su) COLOR=$DEFCOL1 ;; # <-- Su="Sunday" Sa) COLOR=$DEFCOL2 ;; # <-- Sa="Saturday" * ) COLOR=$DEFCOL3 ;; # <-- other days of the week esac Y=$(((6-(WDAY1+d-1)/7)*(PTSIZE+5))) echo "-fill $SHADOW -draw 'text $X,$Y \"$d\"' \\" echo "-fill $COLOR -draw 'text $(($X-1)),$(($Y-1)) \"$d\"' \\" done if [ ! "${PICTURE%/*}" = "${PICTURE##*/}" ]; then echo "\"${PICTURE}\" \"${PICTURE%/*}/${PREFIX}-${PICTURE##*/}\" " else echo "\"${PICTURE}\" \"${PREFIX}-${PICTURE##*/}\" " fi