Byggvir of Barley Published on December 19, 2008
by Byggvir of Barleypro

Byggvir of Barley's blog

Browse posts
Self Framed - how was it done?
Posted on December 29, 2008
8 comments (latest 11 months ago)
Smiley - how was it done?
Posted on December 27, 2008
10 comments (latest 11 months ago)
GIF-Bilder
Posted on December 23, 2008
2 comments (latest 11 months ago)
Kalender (improved)
Posted on December 20, 2008
Calendar - how was it done?
8 comments (latest 11 months ago)
GIF-Spielerei
Posted on December 17, 2008
4 comments (latest 11 months ago)
40.000 vistits
Posted on December 16, 2008
6 comments (latest 11 months ago)
How it was done!
Posted on December 14, 2008
6 comments (latest 10 months ago)
Eine schönen zweiten Advent
Posted on December 7, 2008
3 comments (latest 12 months ago)

More information

This post is public
Attribution + non Commercial + share Alike
  1. 1 person added it to his favorites
  2. Read 266 times

Calendar - how was it done?

Friday December 19, 2008 at 01:57PM

January 2009
January 2009
To create the calender-page I used the followin script, which creates the ImageMagick "convert"-command. The picture is created with following command:

convert 2009 1 bild.jpg | sh

calendar 2009 1 bild.jpg | sh

First parameter is the year, second the month with January = 1 and the third is the name of the picture.

If you call only "calendar 2009 1 bild.jpg" the script will type the convert command with all parameters on stdout.


Save the following script as calendar. Make it executable with "chmod u+x calendar". The script will type the "convert"-command with Parameters to stdout, to produce the picture pipe the output to a shell.

PS: Download here http://www.ipernity.com/doc/20310/3694701?from=3694701&at=1229982134

#!/bin/sh

[ $# -lt 3 ] && echo "usage calender 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 mmonth
DINM=(31 28 31 30 31 30 31 31 30 31 30 31)
# Define the names ot the days
NOFD=(So Mo Di Mi Do Fr Sa)
NOFM=(Januar Februar März April Mai Juni Juli August September Oktober November Dezember)

PREFIX="ip"
FONT="Andy MT"
PTSIZE=$((H/40))
SIGN="© 2008,2009 by Byggvir of Barley"

echo -e "convert \\"
echo -e "-gravity North \\"
echo -e "-pointsize 128 -family \"$FONT\" \\"
echo -e "-fill Black -draw 'text 32,8 \"${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\" \\"

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
   So) COLOR=Red ;;
   Sa) COLOR=MediumVioletRed ;;
   * ) COLOR=Lightgrey ;;
  esac
  echo "-fill Black -draw 'text $X,$Y \"$WDAY\"' \\"
  echo "-fill $COLOR -draw " "'text $(($X-1)),$(($Y-1)) \"$WDAY\"' \\"
  Y=$((H-2*PTSIZE))
  echo "-fill Black -draw 'text $X,$Y \"$d\"' \\"
  echo "-fill $COLOR -draw 'text $(($X-1)),$(($Y-1)) \"$d\"' \\"
done
echo "${PICTURE} ${PREFIX}-${PICTURE}"

8 Comments / add your comment?

Byggvir of Barleypro says:
BTW: The formating of the source code was done with "kate" export to html and copied in the text editor window in source view.
Posted 11 months ago. ( permalink )
wdjpro says:
Very cool - thanks!
Posted 11 months ago. ( permalink )
Gartenfreuden (Wolfgang)pro says:
Kannst Du mir etwas Hilfe geben. Ich bekomme es nicht hin. Einfache Befehle bei ImageMagick klappen ja noch. Aber wie binde ich das Script ein? Das Script habe ich abgespeichert als kalender.sh,und ausführbar. richtig oder falsch?? Im Terminal (Ubuntu) bin ich ins aktuelle Verzeichnis gewechselt. Bild habe ich bild.jpg benannt. Im Terminal habe ich dann den convert Befehl mit den drei Paramern eingegeben sowie Pipe kalender.sh. Klappte aber nicht? Was mache ich falsch? Würde mich freuen, wenn Du mir hilfst.
Posted 11 months ago. ( permalink / translate )
Byggvir of Barleypro replies:
Entschuldige, mein Fehler, da ist mir ein Tyco unterlaufen. Du hast alles richtig gemacht, nur musst du "kalender.sh" mit den drei Parametern aufrufen. Der Name des Bildes ist beliebig.

Der erste Parameter ist das Jahr. der zweite der Monat mit Januar = 1, der dritte Parameter ist das Bild.

Es funktioniert nur mit querformatigen Bildern vernünftig. Für Hochformat muss die PTSIZE anders berechnet werden. Siehe www.ipernity.com/blog/byggvir/116046.

Für Hooch- und Querformat ersteze die Zeile mit "PTSIZE=" durch

PTSIZE=$(((W>H?H:W)/40))
Posted 11 months ago. ( permalink )
Byggvir of Barleypro says:
Posted 11 months ago. ( permalink / translate )
wdjpro says:
Each time I run this, I get a syntax error pointing to this line:

DINM=(31 28 31 30 31 30 31 31 30 31 30 31)

(something about an unexpected "("). Does this make sense?
Posted 11 months ago. ( permalink )
Byggvir of Barleypro replies:
I remember such a message while developing the script. It doesN't make sense.

Did you copied it from the web-page or did you download the zip file.

BTW: I miss forgot to adjust the number of days in a month in leap years.

For leap years you have to add after DINM=( 31 ...)

This works fine except for 1700, 1800, 1900, 2100, 2200, 2300, 2500 ...

if [ $((YEAR % 4)) -eq 0 ]
then
DINM[1]=29
fi
Posted 11 months ago. ( permalink )
Byggvir of Barleypro says:
This is the lastest version. Please download the zipped version.


#!/bin/sh

[ $# -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 mmonth
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 names ot the days
NOFD=(So Mo Di Mi Do Fr Sa)
NOFM=(Januar Februar März April Mai Juni Juli August September Oktober November Dezember)

PREFIX="ip"
FONT="Andy MT"
PTSIZE=$(((W>H?H:W)/40))
SIGN="© 2008,2009 by Byggvir of Barley"

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\" \\"

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
So) COLOR=Red ;;
Sa) COLOR=MediumVioletRed ;;
* ) COLOR=Black ;;
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##*/}\" "
Posted 11 months ago. ( permalink )

Add your comment

Reply to this comment

Edit your comment

Please sign in to post a comment Sign in now?


rss Latest comments – Subscribe to the feed of comments related to this post.

 

Català | Čeština nové | 中文 | Deutsch | English | Español | Esperanto | Ελληνικά | Français | Galego | Italiano | Nederlands | Português | More...