The imagecopy() function is used to copy part of an image.
Syntax
imagecopy( dst_img, src_img, dst_x, dst_y, src_x, src_y, src_w, src_h)
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.
Return
The imagecopy() function returns TRUE on success or FALSE on failure.
Example
The following is an example:
<?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); ?>
Output
The following is the output:
Example
Let us see another example wherein part of an image is copied:
<?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); ?>
Output
The following is the output: