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

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


ฟังก์ชัน imagecolorexact() หา index ของสีที่ระบุใน palette อย่างแม่นยำ

ไวยากรณ์

imagecolorexact($img, $red, $green, $blue)

พารามิเตอร์

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

คืนค่า

Index ของสีใน palette หรือ -1 ถ้าไม่มีสีนั้น

ตัวอย่าง

<?php 
$img = imagecreatefrompng('https://www.tutorialspoint.com/assets/videos/courses/67/images/course_67_image.png'); 
$colors = array(); 
$colors[] = imagecolorexact($img, 30, 90, 50); 
$colors[] = imagecolorexact($img, 80, 120, 100); 
$colors[] = imagecolorexact($img, 25, 80, 50); 
print_r($colors); 
imagedestroy($img); 
?>

ผลลัพธ์

Array ( [0] => 1989170 [1] => 5273700 [2] => 1658930 )