imagecopy 


gd apg

COPY an entire or part image over another image.





This function copy a part of $src_imageage onto $dst_imageage 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 $dst_x and $dst_y.

This function returns TRUE on success or FALSE on failure.



<?php

bool imagecopy 
GdImage $dst_image,  
                             
GdImage $src_image
                                       
int $dst_xint $dst_y
                                       
int $src_xint $src_y
                                       
int $src_widthint $src_height )


where,

$dst_image The destination image identifier

$src_image 
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 

?>
 

  $dst_image   


The destination image link resource or object.



  $src_image   


The source image link resource or object.



  $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.



  1 EXERCISE   

<?php

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

$base_img01 "jpeg/JPEG 021 01 CERN.jpg";

$fram_img01 "jpeg/JPEG 021 01(frame).jpg";

$dest_img01 "jpeg/JPEG 021 01(in frame).jpg";

echo 
$base_img01?><br><br>
<img src="<?php echo $base_img01?>"
 alt="<?php echo $base_img01?>
 title="<?php echo $base_img01?>"><br><br>
 
 <?php echo $fram_img01?><br><br>
<img src="<?php echo $fram_img01?>"
 alt="<?php echo $fram_img01?>
 title="<?php echo $fram_img01?>"><br><br><br> 
<?php
$id_base01 
imagecreatefromjpeg($base_img01);

$id_fram01 imagecreatefromjpeg($fram_img01);

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

$base_x01 0;
$base_y01 0;

$fram_x01 15;
$fram_y01 15;

imagecopy($id_fram01$id_base01
                                      
$fram_x01$fram_y01
                                      
$base_x01$base_y01
                                      
$base_w01$base_h01);
                                      
imagejpeg($id_fram01$dest_img01);

echo 
$dest_img01?><br><br>
<img src="<?php echo $dest_img01?>"
 alt="<?php echo $dest_img01?>
 title="<?php echo $dest_img01?>">
 
 

 RESULT   

JPEG 021 01 CERN.jpg

JPEG 021 01 CERN.jpg apr


JPEG 021 01(frame).jpg

JPEG 021 01(frame).jpg apr


JPEG 021 01(in frame).jpg

JPEG 021 01(in frame).jpg apr

  2 EXERCISE   

<?php

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

$base_img02 "png/PNG 039 02 CERN.png";

$fram_img02 "png/PNG 039 02(frame).png";

$dest_img02 "png/PNG 039 02(in frame).png";

echo 
$base_img02?><br><br>
<img src="<?php echo $base_img02?>"
 alt="<?php echo $base_img02?>
 title="<?php echo $base_img02?>"><br><br>
 
 <?php echo $fram_img02?><br><br>
<img src="<?php echo $fram_img02?>"
 alt="<?php echo $fram_img02?>
 title="<?php echo $fram_img02?>"><br><br><br> 
<?php
$id_base02 
imagecreatefrompng($base_img02);

$id_fram02 imagecreatefrompng($fram_img02);

$base_w02 imagesx($id_base02) - 150;
$base_h02 imagesy($id_base02) - 150;

$base_x02 0;
$base_y02 10;

$fram_x02 100;
$fram_y02 100;

imagecopy($id_fram02$id_base02
                                      
$fram_x02$fram_y02
                                      
$base_x02$base_y02
                                      
$base_w02$base_h02);
imagepng($id_fram02$dest_img02);

echo 
$dest_img02?><br><br>
<img src="<?php echo $dest_img02?>"
 alt="<?php echo $dest_img02?>
 title="<?php echo $dest_img02?>">
 

 RESULT   

PNG 039 02 CERN.png

PNG 039 02 CERN.png apr


PNG 039 02(frame).png

PNG 039 02(frame).png apr


PNG 039 02(in frame).png

PNG 039 02(in frame).png apr