ฟังก์ชัน imagecolorallocatealpha() จัดสรรสีพร้อม alpha (ความโปร่งใส) ให้ภาพ
ไวยากรณ์
imagecolorallocatealpha(img, red, green, blue, alpha)
พารามิเตอร์
- img: Image resource จาก imagecreatetruecolor()
- red: สีแดง
- green: สีเขียว
- blue: สีน้ำเงิน
- alpha: ความโปร่งใส 0 = ทึบ, 127 = โปร่งใสเต็มที่
คืนค่า
Color identifier หรือ FALSE ถ้าล้มเหลว
ตัวอย่าง
<?php
$img = imagecreatetruecolor(520, 350);
$bgcolor = imagecolorallocate($img, 50, 10, 255);
imagefill($img, 0, 0, $bgcolor);
$one = imagecolorallocatealpha($img, 50, 255, 0, 70);
$two = imagecolorallocatealpha($img, 255, 0, 255, 50);
$three = imagecolorallocatealpha($img, 150, 255, 0, 60);
$four = imagecolorallocatealpha($img, 200, 0, 255, 90);
imagefilledellipse($img, 200, 150, 150, 150, $one);
imagefilledellipse($img, 220, 150, 150, 150, $two);
imagefilledellipse($img, 240, 150, 150, 150, $three);
imagefilledellipse($img, 280, 150, 150, 150, $four);
header('Content-Type: image/png');
imagepng($img);
imagedestroy($img);
?>
ผลลัพธ์
