PHP gd generate calendar diagram

Source: Internet
Author: User

1<?PHP2 3 //If you submitted a time, display the calendar of your submission, otherwise the current month calendar is displayed4 if(isset($_get[' Month ']) &&isset($_get[' Year ']))5 {6     $month=$_get[' Month '];7     $year=$_get[' Year '];8 }9 Else Ten { One     $month=Date(' m '); A     $year=Date(' Y '); - } - $weekid=Date(' W ',Mktime(0,0,0,$month, 1,$year));//the first day of the month in a certain year is the week. 0-7 stands for Sunday-Saturday respectively the $countdays=Date(' t ',Mktime(0,0,0,$month, 1,$year));//number of days in a certain month of the year - //Get the number of days last month - $prevMonth=$month-1; - $prevYear=$year; + if($prevMonth= = 0){ -     $prevMonth= 12; +     $prevYear=$year-1; A } at $prevMonthDays=Date(' t ',Mktime(0,0,0,$prevMonth, 1,$prevYear));//the number of months of the month in a certain year - //echo $prevMonthDays. " <br/> "; - //echo $prevMonth. " <br/> "; - $countdays=Date(' t ',Mktime(0,0,0,$month, 1,$year));//number of days in a certain month of the year - $arr _days=Array();//array $arr_days represents each day of a month - //echo $weekid. " <br/> "; in //echo $countdays. " <br/> "; - //print_r ($arr _days); to $tempweekid=$weekid-1;//used to calculate the number of days before last month + //Initialize array $arr_days -  for($i= 0;$i<= 35;$i++) the { *     if($tempweekid>=0){ $         $arr _days[$i] =$prevMonthDays-$tempweekid;Panax Notoginseng         $tempweekid--; -}Else{ the         $arr _days[$i] = ""; +     } A      the } +  - //Assigning a value to an $arr_days array $  for($i=$weekid,$j= 1;$j<=$countdays;$i++,$j++) $ { -     $arr _days[$i] =$j; - } the  - Header("Content-type:image/png");Wuyi $im= @imagecreate (300, 185) theOr die("Cannot Initialize new GD image Stream"); - $background _color= Imagecolorallocate ($im, 255, 255, 255); Wu  -  About //Create Some colors $ $white= Imagecolorallocate ($im, 255, 255, 255); - $grey= Imagecolorallocate ($im, 128, 128, 128); - $black= Imagecolorallocate ($im, 0, 0, 0); - $red= Imagecolorallocate ($im, 255, 37, 37); A $color 2= Imagecolorallocatealpha ($im, 0,0,0,0); +  the $alphagray= Imagecolorallocatealpha ($im, 205,206,206,0); - $alphared= Imagecolorallocatealpha ($im, 255,206,206,0); $  the $font= './gillsans.ttf '; the $text= "SU"; the  the $titleArray=Array("SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"); - $font _x= 20; in $font _y= 20; the foreach($titleArray  as $key=$value){ the //Add Some shadow to the text AboutImagettftext ($im, 12, 0,$font _x,$font _y,$color 2,$font,$value);  the     $font _x+=40; the } the  +  - $font _x= 20; the $font _y= 45;Bayi  the     //Tabular Output the  for($i= 0;$i<= 35;$i++) - { -     $row=$arr _days[$i]; the     $tempFontx=$font _x; the     if($row< 10){ the         $tempFontx+=5; the     } -      the      the      the     if($i% 7 = = 0)94     { the          the         if($i< 7 &&$row> 7){ theImagettftext ($im, 12, 0,$tempFontx,$font _y,$alphared,$font,$row); 98}Else{ AboutImagettftext ($im, 12, 0,$tempFontx,$font _y,$red,$font,$row);  -         }101         102         103         $font _x+=40;104}Else{ the         if($i< 7 &&$row> 7){106Imagettftext ($im, 12, 0,$tempFontx,$font _y,$alphagray,$font,$row); 107}Else{108Imagettftext ($im, 12, 0,$tempFontx,$font _y,$color 2,$font,$row);109         }     the             111         $font _x+=40; the     }113      the     if(($i+ 1)% 7 = = 0) the     { the         $font _x= 20;117         $font _y+ = 25;118     }119 } - 121 //ADD the text122Imagepng ($im,"./".$year.$month.". png);123 //imagepng ($im);124Imagedestroy ($im);
View Code

The font used FONT:HTTP://PAN.BAIDU.COM/S/1JGBZRM2

Final effect:

Reference article: A simple perpetual calendar implemented in PHP

PHP gd generate calendar diagram

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.