Computer >> Computer tutorials >  >> Programming >> PHP

imagecopymerge() function in PHP


The imagecopymerge() function copy and merge part of an image.

Syntax

imagecopymerge ( dst_img, src_img, dst_x, dst_y, src_x, src_y, src_w, src_h, pct )

Parameters

  • dst_im Set destination image link resource.

  • src_im Set source image link resource.

  • dst_x Set x-coordinate of destination point.

  • dst_y Set y-coordinate of destination point.

  • src_x Set x-coordinate of source point.

  • src_y Set y-coordinate of source point.

  • src_w Set source width.

  • src_h Set source height.

  • pct The two images will be merged according to pct which can range from 0 to 100.

Return

The imagecopymerge() function returns the TRUE on success or FALSE on failure.

Example

The following is an example:

<?php
   $destImg = imagecreatefrompng('https://www.tutorialspoint.com/images/Javascript.png');
   $srcImg = imagecreatefrompng('https://www.tutorialspoint.com/images/java8.png');
   imagecopymerge($destImg, $srcImg, 10, 10, 0, 0, 350, 120, 60);
   header('Content-Type: image/png');
   imagegif($destImg);
   imagedestroy($destImg);
   imagedestroy($srcImg);
?>

Output

The following is the output displaying the merge of two images:

imagecopymerge() function in PHP

Example

Let us see another example wherein images are copied and merged with different coordinates:

<?php
$destImg = imagecreatefrompng('https://www.tutorialspoint.com/images/php.png');
$srcImg = imagecreatefrompng('https://www.tutorialspoint.com/images/Operating-System.png');
   imagecopymerge($destImg, $srcImg, 10, 20, 0, 0, 390, 100, 80);
   header('Content-Type: image/png');
   imagegif($destImg);
   imagedestroy($destImg);
   imagedestroy($srcImg);
?>

Output

The following is the output:

imagecopymerge() function in PHP