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

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


ฟังก์ชัน imagecolorsforindex() ดึงค่าสี (RGBA) ของ palette index ที่ระบุ

ไวยากรณ์

imagecolorsforindex (img, index)

พารามิเตอร์

  • img: ภาพจาก imagecreatetruecolor()
  • Index: palette index

คืนค่า

Associative array มี keys: red, green, blue, alpha

ตัวอย่าง

<?php 
$img = imagecreatefrompng('https://www.tutorialspoint.com/images/tp-logo-diamond.png'); 
$x = 25; $y = 45; 
$rgb = imagecolorat($img, 25, 45); 
$colors = imagecolorsforindex($img, $rgb); 
var_dump($colors); 
?>

ผลลัพธ์

array(4) { ["red"]=> int(255) ["green"]=> int(255) ["blue"]=> int(255) ["alpha"]=> int(127) }