Easy Tutorial
❮ Func Date Default Timezone Get Php Exception ❯

PHP imagecolorsforindex - Get Color at Index

PHP Image Processing

imagecolorsforindex — Get the color of a specified index.

Syntax

array imagecolorsforindex ( resource $image , int $index )

This function returns an associative array with keys for red, green, blue, and alpha, containing the corresponding values for the specified color index.

Example

<?php

// Open an image
$im = imagecreatefrompng('tutorialpro-logo.png');

// Get the color of a point
$start_x = 40;
$start_y = 20;
$color_index = imagecolorat($im, $start_x, $start_y);

// Make it readable
$color_tran = imagecolorsforindex($im, $color_index);

// Display the color values
print_r($color_tran);

?>

The output of the above example is similar to:

Array
(
    [red] => 195
    [green] => 223
    [blue] => 165
    [alpha] => 64
)

Related Articles

PHP Image Processing

❮ Func Date Default Timezone Get Php Exception ❯