PHP 中的 imagecopy() 函数


imagecopy() 函数用于复制图像的一部分。

语法

imagecopy( dst_img, src_img, dst_x, dst_y, src_x, src_y, src_w, src_h)

参数

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

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

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

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

  • src_x 设置源点的 x 坐标。

  • src_y 设置源点的 y 坐标。

  • src_w 设置源宽度。

  • src_h 设置源高度。

返回值

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

示例

以下是一个示例

<?php
   $srcImg = imagecreatefromgif('https://tutorialspoint.com/images/html.gif');
   $dest = imagecreatetruecolor(170, 140);
   imagecopy($dest, $srcImg, 0, 0, 0, 0, 180, 260);
   header('Content-Type: image/gif');
   imagegif($dest);
   imagedestroy($dest);
   imagedestroy(srcImg);
?>

输出

以下是输出

示例

让我们看一个复制图像一部分的其他示例

<?php
   $srcImg = imagecreatefromgif('https://tutorialspoint.com/images/html.gif');
   $dest = imagecreatetruecolor(170, 140);
   imagecopy($dest, $srcImg, 10, 20, 0, 0, 100, 280);
   header('Content-Type: image/gif');
   imagegif($dest);
   imagedestroy($dest);
   imagedestroy(srcImg);
?>

输出

以下是输出

更新于: 31-Dec-2019

740 次查看

开启你的 职业生涯

通过完成本课程获得认证

立即开始
广告
© . All rights reserved.