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="katexmathml"><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/xtex">srcy,</annotation></semantics></math></span><spanclass="katexhtml"ariahidden="true"><spanclass="base"><spanclass="strut"style="height:0.7167em;verticalalign:0.2861em;"></span><spanclass="mordmathnormal"style="marginright:0.02778em;">sr</span><spanclass="mord"><spanclass="mordmathnormal">c</span><spanclass="msupsub"><spanclass="vlisttvlistt2"><spanclass="vlistr"><spanclass="vlist"style="height:0.1514em;"><spanstyle="top:2.55em;marginleft:0em;marginright:0.05em;"><spanclass="pstrut"style="height:2.7em;"></span><spanclass="sizingresetsize6size3mtight"><spanclass="mordmathnormalmtight"style="marginright:0.03588em;">y</span></span></span></span><spanclass="vlists"></span></span><spanclass="vlistr"><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:

Return Value: This function returns True on success or False on failure. Below programs illustrate the imagecopy() function in PHP.Program 1:

php `

`

Output: part of image Program 2:

php `

`

Output: full image Related Articles:

Reference: https://www.php.net/manual/en/function.imagecopy.php