note 53715 rejected from function.mktime by mazzanet
| From: | mazzanet@php.net | Date: | Fri, 10 Jun 2005 10:24:07 +0000 |
| Subject: | note 53715 rejected from function.mktime by mazzanet | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-90219@lists.php.net to get a copy of this message | ||
Note Submitter: shadikka at gmail dot anti dot spam dot com
----
A calendar script. Syntax:
resource imagecalendar (int year, int month,[ int cellsize, int bgimage, bool fullbg, hex bgcolor,
hex linecolor, hex daycolor, hex sundaycolor])
Includes the imagecreatefromext() function, which auto-detects the image type by extension and loads
the image.
Example of running the function included in the bottom.
<?php
function imagecreatefromext($img) {
$ext = substr($img, strrpos($img,".")+1);
switch ($ext) {
case "png":
return imagecreatefrompng($img);
break;
case "jpg":
case "jpeg":
return imagecreatefromjpeg($img);
break;
case "gif":
return imagecreatefromgif($img);
break;
}
return FALSE;
}
function imagecalendar($year, $month, $cs=100, $bgimage="", $fullbg=FALSE,
$bgcolor=0xffffff, $linecolor=0x000000, $daycolor=0x000055, $sundaycolor=0xff0000) {
$wk = array("Mon", "Tue", "Wed", "Thu", "Fri",
"Sat", "Sun");
$day = 1;
$week = 0;
$initialweek = date("W", mktime(0, 0, 0, $month, $day, $year));
$capt = date("F Y", mktime(0, 0, 0, $month, $day, $year));
if ($bgimage) { $bgimg = imagecreatefromext($bgimage); }
while (date((strlen($month) > 1 ? "m" : "n"), mktime(0, 0, 0, $month, $day +
1, $year)) == $month) {
$wd = date("w", mktime(0, 0, 0, $month, $day, $year)) - 1;
$wd = ($wd == -1 ? 6 : $wd);
$table[$week][$wd]=date("d", mktime(0,0,0,$month,$day,$year));
if ($wd == 6) { $week++; }
$day++;
}
$img = imagecreatetruecolor($cs * 7 + 28, $cs * ($week + 1) + ($week + 1) + 31);
imagefilledrectangle($img, 0, 0, imagesx($img), imagesy($img), $bgcolor);
imagestring($img, 4, imagesx($img) / 2 - strlen($capt) * imagefontwidth(4) / 2, -2, $capt,
$linecolor);
if ($bgimg) {
imagecopyresized($img, $bgimg, ($fullbg ? 0 : 20), ($fullbg ? 0 : 30), 0, 0, ($fullbg ?
imagesx($img) : imagesx($img) - 20), ($fullbg ? imagesy($img) : imagesy($img)-30), imagesx($bgimg),
imagesy($bgimg));
}
for ($x = 0; $x < 7; $x++) {
imagestring($img, 3, $x*$cs+$cs/2-imagefontwidth(3)+20, 29-imagefontheight(3), $wk[$x], ($x == 6 ?
$sundaycolor : $daycolor));
}
for ($x = 0; $x < $week + 1; $x++) {
imagestring($img, 3, 16-imagefontwidth(3)*2, $x*$cs+$x+$cs/2 + 30, $initialweek + $x, $daycolor);
}
for ($x = 0; $x < 9; $x++) {
imageline($img, $x*$cs+$x+20, 30, $x*$cs+$x+20, imagesy($img), $linecolor);
}
for ($x = 0; $x < 7; $x++) {
imageline($img, 20, $x*$cs+$x+30, imagesx($img), $x*$cs+$x+30, $linecolor);
}
foreach ($table as $week => $row) {
foreach ($row as $wd => $day) {
imagestring($img, 4, $wd*$cs+$wd+25, $week*$cs+$week+33, date("d", mktime(0, 0, 0,
$month, $day, $year)), ($wd == 6 ? $sundaycolor : $daycolor));
$day2++;
}
}
return $img;
imagedestroy($img);
}
header("Content-type: image/png");
imagepng(imagecalendar(date("Y"), date("m"), 105, 'http://fi.php.net/images/php.gif',
'', 0xffffff, 0x00aaff, 0x0000ff, 0xf00000));
?>