Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> การเขียนโปรแกรม >> PHP

ฟังก์ชัน imagecolorallocate() ใน PHP


ฟังก์ชัน imagecolorallocate() จัดสรรสี RGB ให้ภาพ

ไวยากรณ์

int imagecolorallocate($img, $red, $green, $blue)

พารามิเตอร์

  • img: Image resource จาก imagecreatetruecolor()
  • red: สีแดง (0-255)
  • green: สีเขียว (0-255)
  • blue: สีน้ำเงิน (0-255)

คืนค่า

สีในรูปแบบ RGB (color identifier)

ตัวอย่าง

<?php 
$img = imagecreatetruecolor(600, 220); 
$bgcolor = imagecolorallocate($img, 20, 50, 120); 
imagefill($img, 0, 0, $bgcolor); 
header("Content-type: image/png"); 
imagepng($img); 
imagedestroy($img); 
?>

ผลลัพธ์

ฟังก์ชัน imagecolorallocate() ใน PHP