imagecolorsforindex() function in PHP


The imagecolorsforindex() function gets the colors for an index.

Syntax

imagecolorsforindex ( img, index )

Parameters

  • img: Creates an image with imagecreatetruecolor()

  • Index: Set the color index.

Return

The imagecolorsforindex() function returns an associative array with red, green, blue and alpha keys that contain the appropriate values for the specified color index.

Example

The following is an example

 Live Demo

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

Output

The following is the output:

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

Updated on: 31-Dec-2019

56 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements