ความเห็น: 1
สร้างภาพเพื่อ ??? ด้วย ???
ไม่ได้ต้องการสร้างกระแส ฮิๆๆ
แต่อยากนำเสนออีกหนึ่งวิธีในการสร้างภาพ
สำหรับคนที่สนใจในการพัฒนาโปรแกรม
วิธีการที่ว่านี้คือการสร้างภาพด้วย php gd library
ก่อนอื่นขอแนะนำก่อนนะครับว่า php gd library ใช้ทำอะไรได้บ้าง
php gd library ใช้ในการสร้างภาพ หรือการสร้างกราฟแบบ Dynamic ต่างๆ ขอยกตัวอย่างงานที่ผมและท่านพี่ iHum พัฒนาร่วมกันคือ SEC Temperature Monitoring System
ซึ่งใช้ php gd library ในการสร้างกราฟดังตัวอย่าง
จะเห็นได้ว่าภาพตัวอย่างไม่ใช่ภาพที่วาดตั้งไว้ก่อน แต่เป็นภาพที่สร้างจาก php gd library และเปลี่ยนไปตลอดตามการเรียกใช้ของผู้ใช้
โดยปกติแล้ว php gd library ไม่ได้ติดตั้งมาพร้อมกับ php หรือ apache เราสามารถติดตั้งเพิ่มได้โดยใช้คำสั่ง
yum install php-gd (สำหรับ CentOS หรือ Fedora)
apt-get install php-gd (สำหรับ ubuntu)
สำหรับตัวอย่างในการสร้างภาพ ง่ายๆครับ
<?php
/**
* PHP GD
* create a simple image with GD library
*
*/
//setting the image header in order to proper display the image
header("Content-Type: image/png");
//try to create an image
$im = @imagecreate(800, 600)
or die("Cannot Initialize new GD image stream");
//set the background color of the image
$background_color = imagecolorallocate($im, 0xFF, 0xCC, 0xDD);
//set the color for the text
$text_color = imagecolorallocate($im, 133, 14, 91);
//add the string to the image
imagestring($im, 5, 300, 300, "I'm a pretty picture:))", $text_color);
//outputs the image as png
imagepng($im);
//frees any memory associated with the image
imagedestroy($im);
?>
อ้างอิง http://runnable.com
จะได้ภาพเป็น
หากมีเวลา ค่อยมาต่อกันกับการสร้างกราฟ ง่ายๆ กันครับ :)
Other Posts By This Blogger
- Older « ย้อนรอยเวปศูนย์เครื่องมือวิทยาศา...
- Newer » 3BB อยู่ๆ ก็ Forward port ไม่ได้
10 เมษายน 2558 10:27
#102641
หากมีเวลามาเยี่ยมบ้านนาบ้างเน้อพี่เน้อ อย่าให้คอยเก้อนะพี่อยากมีเสื้อใหม่ ...
อิอิอิ
เราเอง