PHP | imagecolorresolve() Function Last Updated : 23 Aug, 2019 Comments Improve Suggest changes Like Article Like Report 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: int imagecolorresolve ( $image, $red, $green, $blue ) Parameters: This function accepts four parameters as mentioned above and described below: $image: It is returned by one of the image creation functions, such as imagecreatetruecolor(). It is used to create size of image. $red: This parameter is used to set value of red color component. $green: This parameter is used to set value of green color component. $blue: This parameter is used to set value of blue color component. Return Value: This function returns the color index. Below programs illustrate the imagecolorresolve() function in PHP: Program 1: php <?php // Load an image $image = imagecreatefromgif( 'https://media.geeksforgeeks.org/wp-content/uploads/animateImages.gif'); // Get closest colors from the image $colors = array(); $colors[] = imagecolorresolve($image, 167, 75, 55); $colors[] = imagecolorresolve($image, 150, 25, 250); $colors[] = imagecolorresolve($image, 161, 234, 135); $colors[] = imagecolorresolve($image, 143, 255, 254); // Output print_r($colors); imagedestroy($image); ?> Output: Array ( [0] => 187 [1] => 188 [2] => 189 [3] => 190 ) Program 2: php <?php // Load an image $image = imagecreatefrompng( 'https://media.geeksforgeeks.org/wp-content/uploads/col1.png'); // Get closest colors from the image $colors = array( imagecolorresolve($image, 156, 0, 255), imagecolorresolve($image, 0, 255, 200), imagecolorresolve($image, 16, 134, 35), imagecolorresolve($image, 143, 255, 254) ); // Output print_r($colors); imagedestroy($image); ?> Output: Array ( [0] => 10223871 [1] => 65480 [2] => 1082915 [3] => 9437182 ) Related Articles: PHP | imagecolorallocate() Function PHP | imagearc() Function Reference: http://php.net/manual/en/function.imagecolorresolve.php Comment More infoAdvertise with us Next Article PHP | imagecolorresolve() Function V vijay_raj Follow Improve Article Tags : Misc Web Technologies PHP Image-Processing PHP-function +1 More Practice Tags : Misc Similar Reads 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 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 | 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 | imagecolorsforindex() Function 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 funct 2 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 Like