imagecopy

(PHP 4, PHP 5, PHP 7, PHP 8)

imagecopy拷贝图像的一部分

说明

imagecopy(
    GdImage $dst_image,
    GdImage $src_image,
    int $dst_x,
    int $dst_y,
    int $src_x,
    int $src_y,
    int $src_width,
    int $src_height
): bool

从 x、y 坐标 src_xsrc_y 开始,将 src_image 的一部分复制到 dst_image 上,宽度为 src_width,高度为 src_height。定义的部分将被复制到 x,y 坐标 dst_xdst_y 上。

参数

dst_image

目标图象资源。

src_image

源图象资源。

dst_x

目标点的 x 坐标。

dst_y

目标点的 y 坐标。

src_x

源点的 x 坐标。

src_y

源点的 y 坐标。

src_width

源图象的宽度。

src_height

源图象的高度。

返回值

成功时返回 true, 或者在失败时返回 false

更新日志

版本 说明
8.0.0 dst_imagesrc_image 现在需要 GdImage 实例;之前需要 resource

范例

示例 #1 裁剪 PHP.net logo

<?php
// Create image instances
$src = imagecreatefromgif('php.gif');
$dest = imagecreatetruecolor(80, 40);

// Copy
imagecopy($dest, $src, 0, 0, 20, 13, 80, 40);

// Output and free from memory
header('Content-Type: image/gif');
imagegif($dest);

imagedestroy($dest);
imagedestroy($src);
?>

以上例程的输出类似于:

示例输出:裁剪 PHP.net logo

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top