imagecopymergegray() function in PHP


The imagecopymergegray() function is used to copy and merge part of an image with gray scale.

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 src_im will be changed to grayscale according to pct where 0 is fully grayscale and 100 is unchanged.

Return

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

Example

The following is an example:

<?php
   $destImg = imagecreatefromgif('https://www.tutorialspoint.com/images/html.gif');
   $srcImg = imagecreatefromgif('https://www.tutorialspoint.com/images/html.gif');
   imagecopymergegray($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:

Example

Let us see another example wherein we have set different x and y coordinate:

<?php
   $destImg = imagecreatefromgif('https://www.tutorialspoint.com/images/html.gif');
   $srcImg = imagecreatefromgif('https://www.tutorialspoint.com/images/html.gif');
   imagecopymergegray($destImg, $srcImg, 20, 10, 0, 0, 410, 130, 100);
   header('Content-Type: image/png');
   imagegif($destImg);
   imagedestroy($destImg);
   imagedestroy($srcImg);
?>

Output

The following is the output:

Updated on: 31-Dec-2019

29 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements