PHP | imagecolorsforindex() Function Last Updated : 04 Jul, 2021 Comments Improve Suggest changes Like Article Like Report The imagecolorsforindex() function is an inbuilt function in PHP which is used to get the colors at the given index. This function returns an array containing red, green, blue and alpha key values for specified color value.Syntax: array imagecolorsforindex ( $image, $index ) Parameters: This function accepts two parameters as mentioned above and described below: $image: The imagecreatetruecolor() function is used to create an image in a given size. This function creates blank image of given size.$index: This parameter is used to specify the color index. Return Value: This function returns an associative array containing red, green, blue and alpha keys value at the given index. Below programs illustrate the imagecolorsforindex() function in PHP:Program 1: php <?php // store the image in variable. $image = imagecreatefrompng( 'https://media.geeksforgeeks.org/wp-content/uploads/geeksforgeeks-9.png'); // Calculate rgb pixel value at particular point. $rgb = imagecolorat($image, 30, 25); // Assign color name and its value. $colors = imagecolorsforindex($image, $rgb); var_dump($colors); ?> Output: array(4) { ["red"]=> int(34) ["green"]=> int(170) ["blue"]=> int(66) ["alpha"]=> int(0) } Program 2: php <?php // store the image in variable. $image = imagecreatefrompng( 'https://media.geeksforgeeks.org/wp-content/uploads/col1.png'); // index value $index_x = 230; $index_y = 120; // Calculate rgb pixel value at particular point. $rgba_color = imagecolorat($image, $index_x, $index_y); // Assign color name and its value. $colors = imagecolorsforindex($image, $rgba_color); var_dump($colors); ?> Output: array(4) { ["red"]=> int(97) ["green"]=> int(57) ["blue"]=> int(104) ["alpha"]=> int(0) } Related Articles: PHP | imagecolorclosestalpha() FunctionPHP | imagecolorat() function Reference: http://php.net/manual/en/function.imagecolorsforindex.php Comment More infoAdvertise with us Next Article PHP | imagecolorsforindex() Function V vijay_raj Follow Improve Article Tags : Misc Web Technologies PHP Image-Processing PHP-function +1 More Practice Tags : Misc Similar Reads PHP | imagecolorset() Function The imagecolorset() function is an inbuilt function in PHP which is used to set the color for the specified palette index. It is used to specify the index in the palette to the specified color. To perform the actual flood-fill, it is useful to create the flood-fill-like effects in palleted images wi 2 min read PHP | imagecolorresolve() Function The imagecolorresolve() function is an inbuilt function in PHP which is used to get the index of the specified color or its closest possible alternative color. This function returns a color index value for a requested color, either the exact matched color or the closest possible alternative. Syntax: 2 min read PHP | imagecolorexact() Function The imagecolorexact() function is an inbuilt function in PHP which is used to get the index of specified color in the palette of the image. In created image files only used colors in the image are resolved. Colors present only in the palette are not resolved. Syntax: int imagecolorexact ( $image, $r 2 min read PHP | imagecolorstotal() Function The imagecolorstotal() function is an inbuilt function in PHP which is used to find the number of colors in an image's palette. This function returns the number of colors in an image palette. Syntax: int imagecolorstotal ( $image ) Parameters: This function accepts a single parameter $image which is 1 min read PHP | imagecolorat() function The imagecolorat() function is an inbuilt function in PHP which is used to get the index of the color of the pixel. This function returns the pixel value at the specified location.Syntax:Â Â int imagecolorat( $image, $x, $y ) Parameters: This function accepts three parameters as mentioned above and d 2 min read PHP | imagecolorclosest() Function The imagecolorclosest() function is an inbuilt function in PHP which is used to get the index of the closest color in the given image. This function returns the index of the color in the palette of the image which is closest to the specified RGB value. Syntax: int imagecolorclosest( $image, $red, $g 2 min read PHP | imagecolorallocate() Function The imagecolorallocate() function is an inbuilt function in PHP which is used to set the color in an image. This function returns a color which is given in RGB format. Syntax: int imagecolorallocate ( $image, $red, $green, $blue ) Parameters: This function accepts four parameters as mentioned above 2 min read PHP | imagecolortransparent() Function The imagecolortransparent() function is an inbuilt function in PHP which is used to define color as transparent. It sets the color of a transparent image. It returns the identifier of the new transparent color. If an image has no transparent color and color not specified then it returns -1. Syntax: 2 min read PHP | imagestring() Function The imagestring() function is an inbuilt function in PHP which is used to draw the string horizontally. This function draws the string at given position. Syntax: bool imagestring( $image, $font, $x, $y, $string, $color ) Parameters: This function accepts six parameters as mentioned above and describ 2 min read PHP | imagecolorresolvealpha() Function The imagecolorresolvealpha() function is an inbuilt function in PHP which is used to get the index of the specified color and alpha value or its closest possible alternative value. This function returns the index for a requested color, either the exact color or the closest possible alternative color 2 min read Like