Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> PHP

Hàm imagecolorresolve() trong PHP

imagecolorresolve() lấy chỉ số màu (color index) của màu chỉ định hoặc màu gần nhất có trong palette.

Cú pháp

imagecolorresolve(resource $image, int $red, int $green, int $blue): int

Tham số

  • image: Resource GD.
  • red, green, blue: Thành phần RGB (0-255).

Trả về

Chỉ số màu (index) trong palette.

Ví dụ

<?php
$img = imagecreatefromgif('https://example.com/image.gif');
$colors[] = imagecolorresolve($img, 120, 0, 190);
$colors[] = imagecolorresolve($img, 110, 0, 140);
$colors[] = imagecolorresolve($img, 120, 190, 0);
print_r($colors); // Array([0]=>128 [1]=>129 [2]=>130)
imagedestroy($img);
?>