<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> <title>Create a new image from a given part of GD2 file or URL</title> </head> <body><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.imagecreatefromgd2.html">imagecreatefromgd2</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.imagecreatefromgd.html">imagecreatefromgd</a></div> <div class="up"><a href="ref.image.html">GD and Image Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div><hr /><div id="function.imagecreatefromgd2part" class="refentry"> <div class="refnamediv"> <h1 class="refname">imagecreatefromgd2part</h1> <p class="verinfo">(PHP 4 >= 4.0.7, PHP 5)</p><p class="refpurpose"><span class="refname">imagecreatefromgd2part</span> — <span class="dc-title">Create a new image from a given part of GD2 file or URL</span></p> </div> <div class="refsect1 description" id="refsect1-function.imagecreatefromgd2part-description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">resource</span> <span class="methodname"><strong>imagecreatefromgd2part</strong></span> ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$filename</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$srcX</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$srcY</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$width</code></span> , <span class="methodparam"><span class="type">int</span> <code class="parameter">$height</code></span> )</div> <p class="para rdfs-comment"> Create a new image from a given part of GD2 file or URL. </p> <div class="tip"><strong class="tip">Tip</strong><p class="simpara">A URL can be used as a filename with this function if the <a href="filesystem.configuration.html#ini.allow-url-fopen" class="link">fopen wrappers</a> have been enabled. See <span class="function"><a href="function.fopen.html" class="function">fopen()</a></span> for more details on how to specify the filename. See the <a href="wrappers.html" class="xref">Supported Protocols and Wrappers</a> for links to information about what abilities the various wrappers have, notes on their usage, and information on any predefined variables they may provide.</p></div> </div> <div class="refsect1 parameters" id="refsect1-function.imagecreatefromgd2part-parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><em><code class="parameter">filename</code></em></span> <dd> <p class="para"> Path to the GD2 image. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">srcX</code></em></span> <dd> <p class="para"> x-coordinate of source point. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">srcY</code></em></span> <dd> <p class="para"> y-coordinate of source point. </p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">width</code></em></span> <dd> <p class="para">Source width.</p> </dd> </dt> <dt> <span class="term"><em><code class="parameter">height</code></em></span> <dd> <p class="para">Source height.</p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues" id="refsect1-function.imagecreatefromgd2part-returnvalues"> <h3 class="title">Return Values</h3> <p class="para">Returns an image resource identifier on success, <strong><code>FALSE</code></strong> on errors.</p> </div> <div class="refsect1 examples" id="refsect1-function.imagecreatefromgd2part-examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example" id="example-3210"> <p><strong>Example #1 <span class="function"><strong>imagecreatefromgd2part()</strong></span> example</strong></p> <div class="example-contents"> <div class="phpcode"><code><span style="color: #000000"> <span style="color: #0000BB"><?php<br /></span><span style="color: #FF8000">// For this example we need the image size before<br /></span><span style="color: #0000BB">$image </span><span style="color: #007700">= </span><span style="color: #0000BB">getimagesize</span><span style="color: #007700">(</span><span style="color: #DD0000">'./test.gd2'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Create the image instance now we got the image <br />// sizes<br /></span><span style="color: #0000BB">$im </span><span style="color: #007700">= </span><span style="color: #0000BB">imagecreatefromgd2part</span><span style="color: #007700">(</span><span style="color: #DD0000">'./test.gd2'</span><span style="color: #007700">, </span><span style="color: #0000BB">4</span><span style="color: #007700">, </span><span style="color: #0000BB">4</span><span style="color: #007700">, (</span><span style="color: #0000BB">$image</span><span style="color: #007700">[</span><span style="color: #0000BB">0</span><span style="color: #007700">] / </span><span style="color: #0000BB">2</span><span style="color: #007700">) - </span><span style="color: #0000BB">6</span><span style="color: #007700">, (</span><span style="color: #0000BB">$image</span><span style="color: #007700">[</span><span style="color: #0000BB">1</span><span style="color: #007700">] / </span><span style="color: #0000BB">2</span><span style="color: #007700">) - </span><span style="color: #0000BB">6</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// Do an image operation, in this case we emboss the <br />// image if PHP 5+<br /></span><span style="color: #007700">if(</span><span style="color: #0000BB">function_exists</span><span style="color: #007700">(</span><span style="color: #DD0000">'imagefilter'</span><span style="color: #007700">))<br />{<br /> </span><span style="color: #0000BB">imagefilter</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #0000BB">IMG_FILTER_EMBOSS</span><span style="color: #007700">);<br />}<br /><br /></span><span style="color: #FF8000">// Save optimized image<br /></span><span style="color: #0000BB">imagegd2</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">, </span><span style="color: #DD0000">'./test_emboss.gd2'</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">imagedestroy</span><span style="color: #007700">(</span><span style="color: #0000BB">$im</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?></span> </span> </code></div> </div> </div> </p> </div> <div class="refsect1 notes" id="refsect1-function.imagecreatefromgd2part-notes"> <h3 class="title">Notes</h3> <blockquote class="note"><p><strong class="note">Note</strong>: <span class="simpara">This function requires GD 2.0.1 or later (2.0.28 or later is recommended).</span></p></blockquote> <div class="warning"><strong class="warning">Warning</strong><p class="para">Windows versions of PHP prior to PHP 4.3.0 do not support access of remote files via this function, even if <a href="filesystem.configuration.html#ini.allow-url-fopen" class="link">allow_url_fopen</a> is enabled. </p></div> </div> </div><hr /><div class="manualnavbar" style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.imagecreatefromgd2.html">imagecreatefromgd2</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.imagecreatefromgd.html">imagecreatefromgd</a></div> <div class="up"><a href="ref.image.html">GD and Image Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div> </div></body></html>