PHP | imagecolormatch() Function
Last Updated :
23 Aug, 2019
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
$image1 = imagecreatefrompng(
$image2 = imagecreate(imagesx( $image1 ), imagesy( $image1 ));
$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);
echo imagecolormatch( $image1 , $image2 );
imagedestroy( $image1 );
imagedestroy( $image2 );
?>
|
Output:
1
Program 2:
<?php
$image1 = imagecreatefrompng(
$image2 = imagecreate(imagesx( $image1 ), imagesy( $image1 ));
$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)
);
echo imagecolormatch( $image1 , $image2 );
imagedestroy( $image1 );
imagedestroy( $image2 );
?>
|
Output:
1
Related Articles:
Reference: http://php.net/manual/en/function.imagecolormatch.php
Like Article
Suggest improvement
Share your thoughts in the comments
Please Login to comment...