array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'uk', ), 'this' => array ( 0 => 'function.imagecolorat.php', 1 => 'imagecolorat', 2 => 'Get the index of the color of a pixel', ), 'up' => array ( 0 => 'ref.image.php', 1 => 'Функції GD та Image', ), 'prev' => array ( 0 => 'function.imagecolorallocatealpha.php', 1 => 'imagecolorallocatealpha', ), 'next' => array ( 0 => 'function.imagecolorclosest.php', 1 => 'imagecolorclosest', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'en', 'path' => 'reference/image/functions/imagecolorat.xml', ), 'history' => array ( ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); contributors($setup); ?>

imagecolorat

(PHP 4, PHP 5, PHP 7, PHP 8)

imagecoloratGet the index of the color of a pixel

Опис

imagecolorat(GdImage $image, int $x, int $y): int|false

Returns the index of the color of the pixel at the specified location in the image specified by image.

If the image is a truecolor image, this function returns the RGB value of that pixel as integer. Use bitshifting and masking to access the distinct red, green and blue component values:

Параметри

image

Об'єкт GdImage, що повертається однією з функцій створення зображення, такою як imagecreatetruecolor().

x

x-coordinate of the point.

y

y-coordinate of the point.

Значення, що повертаються

Returns the index of the color або false в разі помилки.

Увага

Ця функція може повертати як логічне false, так і не логічне значення, яке прирівнюється до false. Докладніше про це описано в розділі Логічні типи даних. Для перевірки значення, яке повертає ця функція, використовується оператор ===.

Журнал змін

Версія Опис
8.0.0 Тепер image має бути примірником GdImage. Раніше очікувався gd-resource.

Приклади

Приклад #1 Access distinct RGB values

<?php
$im
= imagecreatefrompng("php.png");
$rgb = imagecolorat($im, 10, 15);
$r = ($rgb >> 16) & 0xFF;
$g = ($rgb >> 8) & 0xFF;
$b = $rgb & 0xFF;

var_dump($r, $g, $b);
?>

Поданий вище приклад виведе щось схоже на:

int(119)
int(123)
int(180)

Приклад #2 Human-readable RGB values using imagecolorsforindex()

<?php
$im
= imagecreatefrompng("php.png");
$rgb = imagecolorat($im, 10, 15);

$colors = imagecolorsforindex($im, $rgb);

var_dump($colors);
?>

Поданий вище приклад виведе щось схоже на:

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

Прогляньте також