Sophie

Sophie

distrib > Mageia > 4 > x86_64 > by-pkgid > f800694edefe91adea2624f711a41a2d > files > 3664

php-manual-en-5.5.7-1.mga4.noarch.rpm

<!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>Copy and resize part of an image</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.imagecopyresampled.html">imagecopyresampled</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.imagecreate.html">imagecreate</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.imagecopyresized" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">imagecopyresized</h1>
  <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">imagecopyresized</span> &mdash; <span class="dc-title">Copy and resize part of an image</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.imagecopyresized-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="type">bool</span> <span class="methodname"><strong>imagecopyresized</strong></span>
    ( <span class="methodparam"><span class="type">resource</span> <code class="parameter">$dst_image</code></span>
   , <span class="methodparam"><span class="type">resource</span> <code class="parameter">$src_image</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$dst_x</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$dst_y</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$src_x</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$src_y</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$dst_w</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$dst_h</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$src_w</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$src_h</code></span>
   )</div>

  <p class="para rdfs-comment">
    <span class="function"><strong>imagecopyresized()</strong></span> copies a rectangular
   portion of one image to another image.
   <em><code class="parameter">dst_image</code></em> is the destination image,
   <em><code class="parameter">src_image</code></em> is the source image identifier.
  </p>
  <p class="para">
   In other words,  <span class="function"><strong>imagecopyresized()</strong></span> will take an 
   rectangular area from <em><code class="parameter">src_image</code></em> of width 
   <em><code class="parameter">src_w</code></em> and height <em><code class="parameter">src_h</code></em> at 
   position (<em><code class="parameter">src_x</code></em>,<em><code class="parameter">src_y</code></em>) 
   and place it in a rectangular area of <em><code class="parameter">dst_image</code></em> 
   of width <em><code class="parameter">dst_w</code></em> and height <em><code class="parameter">dst_h</code></em>
   at position (<em><code class="parameter">dst_x</code></em>,<em><code class="parameter">dst_y</code></em>).
  </p>
  <p class="para">
   If the source and destination coordinates and width and heights
   differ, appropriate stretching or shrinking of the image fragment
   will be performed. The coordinates refer to the upper left
   corner. This function can be used to copy regions within the
   same image (if <em><code class="parameter">dst_image</code></em> is the same as
   <em><code class="parameter">src_image</code></em>) but if the regions overlap the
   results will be unpredictable.
  </p>
 </div>

 <div class="refsect1 parameters" id="refsect1-function.imagecopyresized-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>

    <dt>

     <span class="term"><em><code class="parameter">dst_image</code></em></span>
     <dd>

      <p class="para">Destination image link resource.</p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">src_image</code></em></span>
     <dd>

      <p class="para">Source image link resource.</p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">dst_x</code></em></span>
     <dd>

      <p class="para">
       x-coordinate of destination point.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">dst_y</code></em></span>
     <dd>

      <p class="para">
       y-coordinate of destination point.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">src_x</code></em></span>
     <dd>

      <p class="para">
       x-coordinate of source point.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">src_y</code></em></span>
     <dd>

      <p class="para">
       y-coordinate of source point.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">dst_w</code></em></span>
     <dd>

      <p class="para">
       Destination width.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">dst_h</code></em></span>
     <dd>

      <p class="para">
       Destination height.
      </p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">src_w</code></em></span>
     <dd>

      <p class="para">Source width.</p>
     </dd>

    </dt>

    <dt>

     <span class="term"><em><code class="parameter">src_h</code></em></span>
     <dd>

      <p class="para">Source height.</p>
     </dd>

    </dt>

   </dl>

  </p>
 </div>

 <div class="refsect1 returnvalues" id="refsect1-function.imagecopyresized-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <strong><code>TRUE</code></strong> on success or <strong><code>FALSE</code></strong> on failure.
  </p>
 </div>

 <div class="refsect1 examples" id="refsect1-function.imagecopyresized-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
   <div class="example" id="example-3207">
    <p><strong>Example #1 Resizing an image</strong></p>
    <div class="example-contents"><p>
     This example will display the image at half size.
    </p></div>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;File&nbsp;and&nbsp;new&nbsp;size<br /></span><span style="color: #0000BB">$filename&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'test.jpg'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$percent&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0.5</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Content&nbsp;type<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">'Content-Type:&nbsp;image/jpeg'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Get&nbsp;new&nbsp;sizes<br /></span><span style="color: #007700">list(</span><span style="color: #0000BB">$width</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$height</span><span style="color: #007700">)&nbsp;=&nbsp;</span><span style="color: #0000BB">getimagesize</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$newwidth&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$width&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">$percent</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$newheight&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$height&nbsp;</span><span style="color: #007700">*&nbsp;</span><span style="color: #0000BB">$percent</span><span style="color: #007700">;<br /><br /></span><span style="color: #FF8000">//&nbsp;Load<br /></span><span style="color: #0000BB">$thumb&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecreatetruecolor</span><span style="color: #007700">(</span><span style="color: #0000BB">$newwidth</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$newheight</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$source&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">imagecreatefromjpeg</span><span style="color: #007700">(</span><span style="color: #0000BB">$filename</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Resize<br /></span><span style="color: #0000BB">imagecopyresized</span><span style="color: #007700">(</span><span style="color: #0000BB">$thumb</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$source</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$newwidth</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$newheight</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$width</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$height</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">//&nbsp;Output<br /></span><span style="color: #0000BB">imagejpeg</span><span style="color: #007700">(</span><span style="color: #0000BB">$thumb</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>The above example will output
something similar to:</p></div>
    <div class="mediaobject">
     
     <div class="imageobject">
      <img src="images/21009b70229598c6a80eef8b45bf282b-imagecopyresized.jpg" alt="Output of example : Resizing an image" width="47" height="25" />
     </div>
    </div>
    <div class="example-contents"><p>
     The image will be output at half size, though better
     quality could be obtained using  <span class="function"><a href="function.imagecopyresampled.html" class="function">imagecopyresampled()</a></span>.
    </p></div>
   </div>
  </p>
 </div>

 <div class="refsect1 notes" id="refsect1-function.imagecopyresized-notes">
  <h3 class="title">Notes</h3>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
   <p class="para">
    There is a problem due to palette image limitations (255+1 colors).
    Resampling or filtering an image commonly needs more colors than 255, a
    kind of approximation is used to calculate the new resampled pixel and its
    color.  With a palette image we try to allocate a new color, if that
    failed, we choose the closest (in theory) computed color.  This is
    not always the closest visual color. That may produce a weird result, like
    blank (or visually blank) images.  To skip this problem, please use a
    truecolor image as a destination image, such as one created by
     <span class="function"><a href="function.imagecreatetruecolor.html" class="function">imagecreatetruecolor()</a></span>.
   </p>
  </p></blockquote>
 </div>

 <div class="refsect1 seealso" id="refsect1-function.imagecopyresized-seealso">
  <h3 class="title">See Also</h3>
  <p class="para">
    <span class="function"><a href="function.imagecopyresampled.html" class="function" rel="rdfs-seeAlso">imagecopyresampled()</a> - Copy and resize part of an image with resampling</span>
  </p>
 </div>

</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="function.imagecopyresampled.html">imagecopyresampled</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="function.imagecreate.html">imagecreate</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>