imagecopymergegray 


gd apg

COPY and MERGE an entire or part image over another image using the gray scale.





This function copy a part of $src_image onto $dst_image starting at coordinates indicated by $src_x, $src_y with the width $src_width and height $src_height and will be copied at coordinates designated by $dest_x and $dest_y.

This function is identical to imagecopymerge except that when merging it preserves the hue of the source by converting the destination pixels to gray scale before the copy operation.

0 ≤ $pct ≤ 100.

If $pct = 0 is fully grayscale and $pct = 100 is unchanged.

When $pct = 100 this function behaves identically to imagecopy for pallete images, except for ignoring alpha components, while it implements alpha transparency for true colour images.

This function returns TRUE on success or FALSE on failure.



<?php

bool imagecopymergegray 
GdImage $dst_image,
                                             
GdImage $src_image
                                                      
int $dst_xint $dst_y
                                                      
int $src_xint $src_y
                                                      
int $src_width int $src_height 
                                                      
int $pct )

where,

$dst_im The destination image identifier

$src_im 
The source image identifier

$dst_x 
The x-coordinate of destination point 

$dst_y 
The y-coordinate of destination point 

$src_x 
The x-coordinate of source point 

$src_y 
The y-coordinate of source point 

$src_width 
The source width 

$src_height 
The source height

$pct 
The percentage of the two merged images

?>
 

  $dst_im   


The destination image identifier.



  $src_im   


The source image identifier.



  $dst_x   


The x-coordinate of destination point.



  $dst_y   


The y-coordinate of destination point.



  $src_x   


The x-coordinate of source point.



  $src_y   


The y-coordinate of source point.



  $src_width   


The source width.



  $src_height   


The source height.



  $pct   


The percentage of the two merged images.



  1 EXERCISE   

<?php

// RUN this code several times

echo 'PHP VERSION: ' PHP_VERSION '<br><br>';

// $lang = 'pt';
$lang 'en';

$pct01 mt_rand(0100);

$pt "Fundo: $pct01%";
$en "Background: $pct01%";

$seal_img01 "png/Copyright-red&white.png";

$base_img01 "png/PNG 044 01.png"

$dest_img "png/PNG 044 01(copyrighted-gray).png"

echo 
$seal_img01?><br><br>
<img src="<?php echo $seal_img01?>"
 alt="<?php echo $seal_img01?>
 title="<?php echo $seal_img01?>" width="70"><br><br>

<?php echo $base_img01?><br><br>
<img src="<?php echo $base_img01?>"
 alt="<?php echo $base_img01?>
 title="<?php echo $base_img01?>" width="400"><br><br><br> 
<?php
$id_base01 
imagecreatefrompng($base_img01);

$id_seal01 imagecreatefrompng($seal_img01);

$seal_w01 imagesx($id_seal01);
$seal_h01 imagesy($id_seal01);

$base_w01 imagesx($id_base01);
$base_h01 imagesy($id_base01);

$base_x01 imagesx($id_base01) - $seal_w01 5;
$base_y01 imagesy($id_base01) - $seal_h01 55;

imagecopymergegray($id_base01$id_seal01
                                    
$base_x01$base_y01
                                    
00
                                    
$seal_w01$seal_h01
                                    
$pct01);

imagepng($id_base01$dest_img);

echo 
$dest_img '<br><br>' .$$lang?><br><br>
<img src="<?php echo $dest_img?>"
 alt="<?php echo $dest_img?>
 title="<?php echo $dest_img?>" width="400">
 
 

 RESULT   

Copyright-red&white.png

Copyright-red&white.png apr

PNG 044 01.png

PNG 044 01.png apr


PNG 044 01(copyrighted-gray).png

Background: 74%

PNG 044 01(copyrighted-gray).png apr

This is a particular result.

For each new run a new result is shown.