|  | การวาดนาฬิกาเข็มในรูปแบบ gif |  | 
| ข้อควรทราบ | 
| 
 | 
| ผลลัพธ์ของโปรแกรมนี้ - วาดนาฬิกาเข็มในรูปแบบ gif | 
| ผลลัพธ์ที่ต้องการ | คำสั่งเรียก tstclock.php3 ใน html ทั่วไป | 
|  | คำสั่งข้างล่างนี้ใช้วาดรูปนาฬิกา <img src=http://www.thaiall.com/php/tstclock.php3> คำสั่งข้างล่างนี้ใช้วาดรูปแสดงตัวอย่างคำสั่ง graphic สำหรับสร้างนาฬิกา <img src=http://www.thaiall.com/php/tstclock1.php3> รวมคำสั่งสำคัญสำหรับคำนวณเวลา <img src=http://www.thaiall.com/php/tstclock2.php3> | 
| รวมคำสั่งสำคัญสำหรับระบบ graphic ในการสร้างนาฬิกา | 
| Source code ของ tstclock1.php3 | 
| 
<?php
        header("Content-type: image/png");
        $imagesize = 80;
        $myImage = ImageCreate($imagesize, $imagesize);
        $white = ImageColorAllocate($myImage, 255, 255, 255);
        $red = ImageColorAllocate($myImage, 255, 0, 0);
        ImageFill($myImage, 0, 0, $red);
        Imageinterlace($myImage, 1);
        Imagearc($myImage, 40, 30, 20, 10, 0, 359, $white);
        ImageLine($myImage, 5, 5, 70, 60, $white);
        Imagestring($myImage, 3, 5, 40, ("This กขค."), $white);
        Imagepng($myImage);
        Imagedestroy($myImage);
?>
Click here เพื่อดูผลการทำงานของโปรแกรม tstclock1.php3 ในหน้าต่างใหม่ | 
| รวมคำสั่งสำคัญสำหรับคำนวณเวลา | 
| Source code ของ tstclock2.php3 | 
| 
<?php
        header("Content-type: image/png");
        $imSize = 80;
        $today = getdate();
        $hour = $today[hours];
        $minutes = $today[minutes];
        $seconds = $today[seconds];
        if ($hour >= 12)  { $hour  -= 12;  }
        //*	change radians and draw circle
        $myImage = ImageCreate($imSize, $imSize);
        $blue = ImageColorAllocate($myImage, 0, 0, 255);
        $yellow = ImageColorAllocate($myImage, 255, 255, 0);
        ImageFill($myImage, 0, 0, $blue);
        Imageinterlace($myImage, 1);
        //*	draw time character
        if ($minutes < 10)  { $minutes="0$minutes";}
        Imagestring($myImage, 4, 6, $imSize - 20, ($hour . ":" . $minutes), $yellow);
        Imagepng($myImage);
        Imagedestroy($myImage);
?>
Click here เพื่อดูผลการทำงานของโปรแกรม tstclock2.php3 ในหน้าต่างใหม | 
| โปรแกรม php3 ที่ใช้เขียน นาฬิกา | 
| Source code ของ tstclock.php3 | 
| 
<?php
        header("Content-type: image/png");
        $imSize = 80;
        $clockSize = $imSize - 8;
        $today = getdate();
        $hour = $today[hours];
        $minutes = $today[minutes];
        $seconds = $today[seconds];
        if ($hour >= 12)  { $hour  -= 12;  }
        $hourDegress = $hour * 30;
        $hourDegress += $minutes / 2;
        $minDegress = $minutes * 6;
        //*	start at 3:00 or degree 90
        $hourDegress  -= 90;
        if ($hourDegress < 0)  {  $hourDegress += 360;  }
        $minDegress   -=  90;
        if ($minDegress < 0)  {  $minDegress += 360;  }
        //*	change radians and draw circle
        $hourRadians = $hourDegress / 57.295779513082;
        $minRadians = $minDegress / 57.295779513082;
        $myImage = ImageCreate($imSize, $imSize);
        $white = ImageColorAllocate($myImage, 255, 255, 255);
        $blue = ImageColorAllocate($myImage, 0, 0, 255);
        $yellow = ImageColorAllocate($myImage, 255, 255, 0);
        ImageFill($myImage, 0, 0, $blue);
        Imageinterlace($myImage, 1);
        Imagearc($myImage, $imSize/2, $imSize/2, $clockSize, $clockSize, 0, 359, $yellow);
        //*	draw the hour line and minute line
        $hourHandLen = ($clockSize / 2) * 0.6;
        $x2 = $imSize/2 + ($hourHandLen * cos($hourRadians));
        $y2 = $imSize/2 + ($hourHandLen * sin($hourRadians));
        ImageLine($myImage, $imSize/2, $imSize/2, $x2, $y2, $white);
        $minHandLen = ($clockSize / 2) * 0.9;
        $x2 = $imSize/2 + ($minHandLen * cos($minRadians));
        $y2 = $imSize/2 + ($minHandLen * sin($minRadians));
        ImageLine($myImage, $imSize/2, $imSize/2, $x2, $y2, $white);
        //*	draw time character
        if ($minutes < 10)  { $minutes="0$minutes";}
        Imagestring($myImage, 3, 5, $imSize - 15, ($hour . ":" . $minutes), $white);
        Imagepng($myImage);
        Imagedestroy($myImage);
?>
Click here เพื่อดูผลการทำงานของโปรแกรม tstclock.php3 ในหน้าต่างใหม | 
| แบบฝึกหัด | 
| 
 | 
|  | + ผู้สนับสนุน + รับผู้สนับสนุน |