PHP Imagecolormatch () Function

PHP

Syntax:
bool imagecolormatch ($image1, $image2)
Parameters: this function takes two parameters as above and described below:
  • $image1:is returned by one of the image creation functions such as imagecreatetruecolor(). Used to create the size of the image.
  • $image2:this is a palette image linking an asset pointing to an image the same size as image1.
Return Value:This function returns True on success or False on failure.The following programs illustrate the imagecolormatch() functionin PHP: Program 1:  
// Set true color and image palette $image1 = imagecreatefrompng ( ' https://media.engineerforengineer.org/wp-content/uploads /col1.png ' );  
// A palette of images created with the 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 to the true color image echo imagecolormatch ( $image1 , $image2 );  
// Free from memory imagedestroy ( $image1 ); imagedestroy ( $image2 ); ?>
Output:
1
Program 2:  
// Set true color and image palette $image1 = imagecreatefrompng ( ' https://media.engineerforengineer.org/wp-content/uploads/col1.png ' );  
// A palette of images created with the 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 to 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
Link: http://php.net/manual/en/function.imagecolormatch.php



Get Solution for free from DataCamp guru