PHP | imagecopy() Function (original) (raw)
Last Updated : 11 Jul, 2025
The imagecopy() function is an inbuilt function in PHP which is used to copy the image or part of image. This function returns true on success or false on failure.Syntax:
bool imagecopy ( dstimage,dst_image, dstimage,src_image, dstx,dst_x, dstx,dst_y, srcx,<spanclass="katex"><spanclass="katex−mathml"><mathxmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>r</mi><msub><mi>c</mi><mi>y</mi></msub><moseparator="true">,</mo></mrow><annotationencoding="application/x−tex">srcy,</annotation></semantics></math></span><spanclass="katex−html"aria−hidden="true"><spanclass="base"><spanclass="strut"style="height:0.7167em;vertical−align:−0.2861em;"></span><spanclass="mordmathnormal"style="margin−right:0.02778em;">sr</span><spanclass="mord"><spanclass="mordmathnormal">c</span><spanclass="msupsub"><spanclass="vlist−tvlist−t2"><spanclass="vlist−r"><spanclass="vlist"style="height:0.1514em;"><spanstyle="top:−2.55em;margin−left:0em;margin−right:0.05em;"><spanclass="pstrut"style="height:2.7em;"></span><spanclass="sizingreset−size6size3mtight"><spanclass="mordmathnormalmtight"style="margin−right:0.03588em;">y</span></span></span></span><spanclass="vlist−s"></span></span><spanclass="vlist−r"><spanclass="vlist"style="height:0.2861em;"><span></span></span></span></span></span></span><spanclass="mpunct">,</span></span></span></span>srcw,src_x, <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>r</mi><msub><mi>c</mi><mi>y</mi></msub><mo separator="true">,</mo></mrow><annotation encoding="application/x-tex">src_y, </annotation></semantics></math></span><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.7167em;vertical-align:-0.2861em;"></span><span class="mord mathnormal" style="margin-right:0.02778em;">sr</span><span class="mord"><span class="mord mathnormal">c</span><span class="msupsub"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.1514em;"><span style="top:-2.55em;margin-left:0em;margin-right:0.05em;"><span class="pstrut" style="height:2.7em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mathnormal mtight" style="margin-right:0.03588em;">y</span></span></span></span><span class="vlist-s"></span></span><span class="vlist-r"><span class="vlist" style="height:0.2861em;"><span></span></span></span></span></span></span><span class="mpunct">,</span></span></span></span>src_w, srcx,<spanclass="katex"><spanclass="katex−mathml"><mathxmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>s</mi><mi>r</mi><msub><mi>c</mi><mi>y</mi></msub><moseparator="true">,</mo></mrow><annotationencoding="application/x−tex">srcy,</annotation></semantics></math></span><spanclass="katex−html"aria−hidden="true"><spanclass="base"><spanclass="strut"style="height:0.7167em;vertical−align:−0.2861em;"></span><spanclass="mordmathnormal"style="margin−right:0.02778em;">sr</span><spanclass="mord"><spanclass="mordmathnormal">c</span><spanclass="msupsub"><spanclass="vlist−tvlist−t2"><spanclass="vlist−r"><spanclass="vlist"style="height:0.1514em;"><spanstyle="top:−2.55em;margin−left:0em;margin−right:0.05em;"><spanclass="pstrut"style="height:2.7em;"></span><spanclass="sizingreset−size6size3mtight"><spanclass="mordmathnormalmtight"style="margin−right:0.03588em;">y</span></span></span></span><spanclass="vlist−s"></span></span><spanclass="vlist−r"><spanclass="vlist"style="height:0.2861em;"><span></span></span></span></span></span></span><spanclass="mpunct">,</span></span></span></span>srcw,src_h )
Parameters: This function accepts eight parameters as mentioned above and described below:
- $dst_image: This parameter is used to set destination image link resource.
- $src_image: This parameter is used to set source image link resource.
- $dst_x: This parameter is used to set x-coordinate of destination point.
- $dst_y: This parameter is used to set y-coordinate of destination point.
- $src_x: This parameter is used to set x-coordinate of source point.
- $src_y: This parameter is used to set x-coordinate of source point.
- $src_w: This parameter is used to set source width.
- $src_h: This parameter is used to set source height.
Return Value: This function returns True on success or False on failure. Below programs illustrate the imagecopy() function in PHP.Program 1:
php `
`
Output:
Program 2:
php `
`
Output:
Related Articles:
Reference: https://www.php.net/manual/en/function.imagecopy.php