PHP | imagepalettecopy() function
Last Updated :
31 Jan, 2020
The imagepalettecopy() function is an inbuilt function in PHP which is used to copy the palette from one image to another.
Syntax:
void imagepalettecopy( resource $destination, resource $source )
Parameters:This function accepts two parameters as mentioned above and described below:
- $destination: It specifies the destination image resource.
- $source: It specifies the source image resource.
Return Value: This function returns nothing.
Below given programs illustrate the imagepalettecopy() function in PHP:
Program 1:
<?php
$palette1 = imagecreate(700, 200);
$palette2 = imagecreate(700, 200);
$green = imagecolorallocate( $palette1 , 0, 255, 0);
imagefilledrectangle( $palette1 , 0, 0, 99, 99, $green );
imagepalettecopy( $palette2 , $palette1 );
header( 'Content-type: image/png' );
imagepng( $palette2 );
?>
|
Output:
Program 2:
<?php
$palette1 = imagecreate(700, 200);
$palette2 = imagecreate(700, 200);
$green = imagecolorallocate( $palette1 , 0, 255, 0);
imagefilledrectangle( $palette1 , 0, 0, 99, 99, $green );
imagepalettecopy( $palette2 , $palette1 );
$color1 = imagecolorstotal( $palette1 );
$color2 = imagecolorstotal( $palette2 );
echo "Number of colors at image 1 is " . $color1 . "<br>" ;
echo "Number of colors at image 2 is " . $color2 ;
?>
|
Output:
Number of colors at image 1 is 1
Number of colors at image 2 is 1
Reference: https://www.php.net/manual/en/function.imagepalettecopy.php
Share your thoughts in the comments
Please Login to comment...