PHP | imagecolormatch() Function Last Updated : 11 Jul, 2025 Comments Improve Suggest changes Like Article Like Report The imagecolormatch() function is an inbuilt function in PHP which is used to make the color of palette version of an image more closely match the true color version. This function returns true on success or false on failure. Syntax: bool imagecolormatch ( $image1, $image2 ) Parameters: This function accepts two parameters as mentioned above and described below: $image1: It is returned by one of the image creation functions, such as imagecreatetruecolor(). It is used to create size of image. $image2: It is the palette image links the resource pointing to an image of the same size as image1. Return Value: This function returns True on success or False on failure. Below programs illustrate the imagecolormatch() function in PHP: Program 1: php <?php // Setup the true color and palette images $image1 = imagecreatefrompng( 'https://media.geeksforgeeks.org/wp-content/uploads/col1.png'); // Palette image created with same size as image1 $image2 = imagecreate(imagesx($image1), imagesy($image1)); // Add some colors to $image2 $color = Array(); $color[] = imagecolorallocate($image2, 152, 0, 231); $color[] = imagecolorallocate($image2, 140, 10, 104); $color[] = imagecolorallocate($image2, 32, 109, 155); $color[] = imagecolorallocate($image2, 184,163, 15); // Match these colors with the true color image echo imagecolormatch($image1, $image2); // Free from memory imagedestroy($image1); imagedestroy($image2); ?> Output: 1 Program 2: php <?php // Setup the true color and palette images $image1 = imagecreatefrompng( 'https://media.geeksforgeeks.org/wp-content/uploads/col1.png'); // Palette image created with same size as image1 $image2 = imagecreate(imagesx($image1), imagesy($image1)); // Add some colors to $image2 $color = Array( $color[] = imagecolorallocate($image2, 25, 136, 147), $color[] = imagecolorallocate($image2, 230, 100, 204), $color[] = imagecolorallocate($image2, 21, 100, 155), $color[] = imagecolorallocate($image2, 41, 63, 234) ); // Match these colors with the true color image echo imagecolormatch($image1, $image2); // Free from memory imagedestroy($image1); imagedestroy($image2); ?> Output: 1 Related Articles: PHP | imagecolortransparent() Function PHP | imageconvolution() Function Reference: https://www.php.net/manual/en/function.imagecolormatch.php Create Quiz Comment V vijay_raj Follow 0 Improve V vijay_raj Follow 0 Improve Article Tags : Misc Web Technologies PHP Image-Processing PHP-function +1 More Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like