ฟังก์ชัน imagecreate() ใช้สำหรับสร้างภาพใหม่ ขอแนะนำให้ใช้ imagecreatetruecolor() เพื่อสร้างภาพแทน imagecreate() เนื่องจากการประมวลผลภาพเกิดขึ้นกับภาพที่มีคุณภาพสูงสุดซึ่งสามารถสร้างได้โดยใช้ imagecreatetruecolor()
ไวยากรณ์
imagecreate( $width, $height )
พารามิเตอร์
-
ความกว้าง :ความกว้างของภาพ
-
ส่วนสูง :ความสูงของภาพ
คืนสินค้า
ฟังก์ชัน imagecreate() ส่งคืนตัวระบุทรัพยากรรูปภาพเมื่อสำเร็จหรือ FALSE จากข้อผิดพลาด
ตัวอย่าง
ต่อไปนี้เป็นตัวอย่าง:
<?php
$img = imagecreate(500, 300);
$bgcolor = imagecolorallocate($img, 150, 200, 180);
$fontcolor = imagecolorallocate($img, 120, 60, 200);
imagestring($img, 12, 150, 120, "Demo Text1", $fontcolor);
imagestring($img, 3, 150, 100, "Demo Text2", $fontcolor);
imagestring($img, 9, 150, 80, "Demo Text3", $fontcolor);
imagestring($img, 12, 150, 60, "Demo Text4", $fontcolor);
header("Content-Type: image/png");
imagepng($img);
imagedestroy($img);
?> ผลลัพธ์
ต่อไปนี้เป็นผลลัพธ์:
