PHP 中的 imagecopymergegray() 函数

phpserver side programmingprogramming更新于 2025/7/6 6:37:17

imagecopymergegray() 函数用于复制并合并灰度图像的部分内容。

语法

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

参数

  • dst_im 
    设置目标图像链接资源。

  • src_im 
    设置源图像链接资源。

  • dst_x
    设置目标图像的 x 坐标点。

  • dst_y 
    设置目标点的 y 坐标。

  • src_x 
    设置源点的 x 坐标。

  • src_y 
    设置源点的 y 坐标。

  • src_w 
    设置源宽度。

  • src_h 
    设置源高度。

  • pct 
    src_im 将根据 pct 转换为灰度,其中 0 为完全灰度,100 为保持不变。

返回

imagecopymergegray() 函数成功时返回 TRUE,失败时返回 FALSE。

示例

以下是示例:

<?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);
?>

输出

输出结果如下:

示例

让我们看另一个示例,其中我们设置了不同的 x 和 y 坐标:

<?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);
?>

输出

输出结果如下:


相关文章