PHP 中的 imagecopy() 函数
phpserver side programmingprogramming更新于 2025/7/6 6:52:17
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://www.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://www.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);
?>
输出
输出结果如下:

