Calendar dates to formatted text file

I have been working on a calendar code using ImageMagick and php and it works but I would like to automate the code a bit more.

Flow:
1/ Create a formated text file of the dates - this is the part I would like to automate.

2/ Save the photos in a folder named in order

3/ Create an image of the information from the text file to go with the month.

4/ Resize the photo and add a border

5/ Put it all together and save as an image.

I could create it as a webpage and print it but you always get the page number, link etc. I HAVE JUST NOTICED YOU CAN TURN THIS OFF BUT YOU STILL NEED TO MESS ABOUT TO GET THE PRINT CORRECT.

Can anyone provide me with a way to create the formatted text file; I have found tutorials/code etc. on how to create a calender for a website but they use tables which I can not do.
Is there another way of creating the calendar image ?

The formated text file needs to look like the bottom half of the image below the month. I do not need the days in the text file if that is easier.

Its not to much work creating the text files and it was just an improvement that would be nice but as I only do one calendar a year its done now.

If anyone is interested in the code to create the calendar image above its:


<?php
/*
The photos need to be numbered in the month order you want them on the calendar
The month details need setting up in the relavent text files
Careful of the font selection as it will be displayed differently
*/

// Setup some defaults
$background = "white";
$font = "arial";
$photo_dir = "photos/";

// Setup the canvas
exec("convert -size 595x842 xc:$background -density 300 -units pixelspercentimeter page.png");

// Read the images into an array in the correct month order
$images = glob( $photo_dir."{*.jpg,*.JPG}", GLOB_BRACE );

// Month array
$months = array('January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');

// Default start month value
$month = 0;

natsort( $images );

// Create the calendar pages
foreach ( $images as $value ){

// Setup the text file name for the month
$text = "text:".$month.".txt";

// Create the days image
$cmd = " -density 300 -background white -fill black -font $font -pointsize 18 $text -trim +repage -resize x250 -unsharp 1.5x1+0.7+0.02";
exec("convert $cmd days.png ");

// Month header
$mon = $months[$month];

// Create the calendar page
$cmd = " page.png ( $value -thumbnail 454x420 -bordercolor black -border 2x2 -bordercolor white -border 2x2 -bordercolor black -border 4x4 ) ".
" -gravity north -geometry +0+50 -composite -gravity center -font $font -pointsize 25 -fill black -annotate +0+85 \\"$mon\\" ".
"  days.png -gravity south -geometry +0+50 -composite ";
exec("convert $cmd calendar/$month.png");

// Display the created page
echo "<img src=\\"calendar/$month.png\\">";

// Increment to the next month
$month++;

}

// Delete the tempory files
Unlink("days.png");
Unlink("page.png");

?>


And the text files need to look something like this ( numbered 0 - 11 ) .


Mon      Tue      Wed      Thu       Fri       Sat       Sun 
                                                          1          2 
  3         4            5         6         7         8          9 
10        11          12       13        14       15         16 
17        18          19       20        21       22         23 
24        25          26       27        28       29         30 
31 

Just thought this was run on a windows localhost; to run on a linux server you will need to escape the ( )


// Create the calendar page
$cmd = " page.png \\( $value -thumbnail 454x420 -bordercolor black -border 2x2 -bordercolor white -border 2x2 -bordercolor black -border 4x4 \\) ".
" -gravity north -geometry +0+50 -composite -gravity center -font $font -pointsize 25 -fill black -annotate +0+85 \\"$mon\\" ".
"  days.png -gravity south -geometry +0+50 -composite ";
exec("convert $cmd calendar/$month.png");