เราจะยกตัวอย่างรูปภาพให้ดูนะครับ
1, สร้างกรอบสีเหลี่ยมซ้อนกัน หลายๆ สี
โค้ด: เลือกทั้งหมด
<?php
header("Content-type: image/gif");
$im = imagecreate( 200, 200 );
$red = imagecolorallocate($im, 255,0,0);
$blue = imagecolorallocate($im, 0,0,255 );
$green = ImageColorAllocate ($im, 0, 255, 0);
imagefilledrectangle($im,19,19,179,179,$blue); //กำหนดขนาดกรอบ สีฟ้า
imagefilledrectangle($im,40,50,155,150,$green); // กำหนดขนาดกรอบสีเขียว
imagegif($im);
?>
โค้ด: เลือกทั้งหมด
<?php
header ("Content-type: image/png");
$im = ImageCreate (150, 150);
$grey = ImageColorAllocate ($im, 230, 230, 230);
$red = ImageColorAllocate ($im, 255, 0, 0);
$green = ImageColorAllocate ($im, 0, 255, 0);
$blue = ImageColorAllocate ($im, 0, 0, 255);
ImageArc($im, 55, 60, 50, 50, 0, 360, $red); //กำหนดขนาดของเส้นสีแดง
ImageArc($im, 85, 60, 50, 50, 0, 360, $green); //กำหนดขนาดของเส้นสีเขียว
ImageArc($im, 70, 85, 50, 50, 0, 360, $blue); //กำหนดขนาดของเส้นสีน้ำเงิน
ImagePng ($im);
ImageDestroy ($im);
?>
โค้ด: เลือกทั้งหมด
<?php
header("Content-type: image/gif");
$im = imagecreate( 200, 200 );
$red = imagecolorallocate($im, 255,0,0);
$blue = imagecolorallocate($im, 0,0,255 );
imageline( $im, 0, 0, 199, 199, $blue ); //กำหนดขนาดเส้นของสีน้ำเงินที่ลากผ่าน
imagegif($im);
?>
อ้างอิง
1 https://www.thesitewizard.com/php/create-image.shtml
2 https://www.php.net/manual/en/function.imagecreate.php
3 https://www.geeksforgeeks.org/php-imagecreate-function/