imageellipse()
รู้หรือไม่ ใน PHP Programming เราสามารถสร้างรูปวาดวงกลมที่เป็นวงกลมได้น่ะครับ จะขนาดความสูงหรือกว้างเท่าไหร่เราสามารถกำหนดได้ โดยใช้ฟังก์ชัน mageellipse () ครับ
ฟังก์ชั่น imageellipse () เป็นฟังก์ชั่นใช้ในการวาดวงรี ฟังก์ชันนี้จะส่งคืน TRUE เมื่อทำงานสำเร็จ หรือค่า FALSE เมื่อเกิดความล้มเหลว
รูปแบบ syntex
imageellipse ( resource $image , int $cx , int $cy , int $width , int $height , int $color ) : bool
พารามิเตอร์:
$image
: แหล่งรูปภาพซึ่งมักจะถูกส่งคืนโดยหนึ่งในฟังก์ชั่นการสร้างภาพเช่น imagecreatetruecolor() ใช้เพื่อสร้างขนาดของภาพ
$cx
: พิกัด x ของศูนย์
$cy
: พิกัด y ของศูนย์
$width
: ความกว้างของวงรี
$height
: ความสูงของวงรี
$color
: สีของวงรี ซึ่งเป็นตัวระบุสีที่สร้างขึ้นโดยฟังก์ชัน imagecolorallocate()
<?php
// It create the size of image or blank image.
$image_size = imagecreatetruecolor(500, 300);
// Set the background color of image.
$background_color = imagecolorallocate($image_size, 255, 255, 255);
// Fill background with above selected color.
imagefill($image_size, 0, 0, $background_color);
// set color of ellipse.
$ellipse_color = imagecolorallocate($image_size, 0, 0, 0);
// Function to draw the ellipse.
imageellipse($image_size, 250, 150, 400, 250, $ellipse_color);
// Output the image.
header("Content-type: image/png");
imagepng($image_size);
?>
ผลลัพธ์ที่ได้
จะเห็นได้ว่าผลลัพธ์ที่ได้จะเป็นรูปทรงวงรี เนื่องจากเราได้กำหนดขนาดความกว้างของวงเท่ากับ 400 น่ะครับ ถ้าหากต้องการให้เป็นวงกลมก็เพียงแค่กำหนดความกว่างและความสูงให้เท่ากัน นอกจากนี้เราสามารถกำหนดสีได้ด้วย ทดลองเล่นกันดูน่ะครับ