################
# Calendar.php - 创建一个当天日期为高亮度的日历GIF图片。
# 使用到了GD 函数库存和TTF字体 -可以被改变成 PNG格式的图片, 当然,如果
# 你想要的是一个拥有一个透明背景的图片除外,这个改动是可以被很容易得
# 完成,最后,我们把图片写到一个叫 dategif/ 的目录,并且用当天的日期来
# 命名该图片的名字。(如:20000204.gif)这个GIF图片一般情况只会有5K或
# 是7K的大小。
#
# 这段程序你可以以任意地方使用,该文档或支持对每个人都是免费的,但是请
# 不要把该程序用于买卖,你可以剪切、拷贝或是毁坏这段程序,只要你喜欢,
# 并且,你不用为了用它而给我付费!如果你需要帮助或是你真的很喜欢这段程
# 序,请给我来封信,以让我知道,你看好吗?
# 二月四日4, 2000 由 Matt Florell ( mattf@mail.com )
################
Header( "Content-type: image/gif");
#创建一幅图片
$im = ImageCreate(156, 142);
# 设置颜色
$black = ImageColorAllocate($im, 50, 50, 50);
$white = ImageColorAllocate($im, 255, 255, 255);
$orange = ImageColorAllocate($im, 255, 200, 0);
$yellow = ImageColorAllocate($im, 255, 255, 0);
$tan = ImageColorAllocate($im, 255, 255, 190);
$grey = ImageColorAllocate($im, 205, 205, 205);
$dkgrey = ImageColorAllocate($im, 140, 140, 140);
###灰线 ###
#边框线
ImageRectangle($im, 1, 1, 155, 141, $dkgrey);
#水平线
ImageRectangle($im, 1, 22, 155, 39, $dkgrey);
ImageRectangle($im, 1, 56, 155, 73, $dkgrey);
ImageRectangle($im, 1, 90, 155, 107, $dkgrey);
ImageRectangle($im, 1, 107, 155, 124, $dkgrey);
#垂直线
ImageRectangle($im, 23, 22, 45, 141, $dkgrey);
ImageRectangle($im, 67, 22, 89, 141, $dkgrey);
ImageRectangle($im, 111, 22, 133, 141, $dkgrey);
### 白线 ###
#外框线
ImageRectangle($im, 0, 0, 154, 140, $white);
#水平线
ImageRectangle($im, 0, 21, 154, 38, $white);
ImageRectangle($im, 0, 55, 154, 72, $white);
ImageRectangle($im, 0, 89, 154, 106, $white);
ImageRectangle($im, 0, 106, 154, 123, $white);
#垂直线
ImageRectangle($im, 22, 21, 44, 140, $white);
ImageRectangle($im, 66, 21, 88, 140, $white);
ImageRectangle($im, 110, 21, 132, 140, $white);
### 在上面写数字
$today = date( "d");
$month = date( "m");
$year = date( "Y");
$datecode = date( "Ymd");
$gif = '.gif';
$first=mktime(0,0,0,$month,1,$year);
$mon_yr=date( "F Y", $first);
$wd=date( "w",$first);
#if ($wd==0) { $wd=7;}
$lastday=date( "d",mktime(0,0,0,$month+1,0,$year));
$cur=-$wd+0;
$ver_position = 50;
for ($k=0;$k<6;$k++) {
$day_position = 5;
$last_row_used = 0;
for ($i=0;$i<7;$i++ ) {
$cur++;
$sing_add = 0;
if (($cur<=0) || ($cur>$lastday) ) $day_position = ($day_position + 22);
else
{
$day_color = $grey;
if ($day_position<10) $day_color = $tan;
if ($cur==$today) $day_color = $yellow;
if (strlen($cur)<2) {$sing_add = 4;}
$fin_position = ($day_position + $sing_add);
ImageTTFText($im, 12, 0, $fin_position, $ver_position, $day_color, "./fonts/arialbd.ttf", "$cur");
$day_position = ($day_position + 22);
$last_row_used = 1;
}
}
$day_position = 5;
if ($last_row_used) $ver_position = ($ver_position + 17);
}
# 月份和年份 (Arial字体、加粗、居中)
$spc = 23;
$st_add = 0;
$st = "$mon_yr";
$st_len = strlen($st);
$st_margin = (14 - $st_len);
if ($st_margin > 0) {$st_add = ($st_margin * 4);}
$spc = ($spc + $st_add);
ImageTTFText($im, 14, 0, $spc, 15, $white, "./fonts/arialbd.ttf", "$st");
# 星期的名字
ImageString($im, 2, 3, 23, "Sun", $orange);
ImageString($im, 2, 25, 23, "Mon", $orange);
ImageString($im, 2, 47, 23, "Tue", $orange);
ImageString($im, 2, 69, 23, "Wed", $orange);
ImageString($im, 2, 91, 23, "Thu", $orange);
ImageString($im, 2, 113, 23, "Fri", $orange);
ImageString($im, 2, 135, 23, "Sat", $orange);
if ($ver_position<140)
{
$im_out = ImageCreate(156, 125);
$out_black = ImageColorAllocate($im_out, 50, 50, 50);
ImageRectangle($im, 1, 124, 155, 124, $dkgrey);
ImageCopyResized($im_out, $im, 0, 0, 0, 0, 156, 125, 156, 125);
ImageColorTransparent($im_out, $out_black);
ImageGIF($im_out, "./dategif/$datecode$gif");
ImageGIF($im_out);
ImageDestroy($im);
ImageDestroy($im_out);
}
else
{
ImageColorTransparent($im, $black);
ImageGif($im, "./dategif/$datecode$gif");
ImageGif($im);
ImageDestroy($im);
}