<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/class.imagick.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'en',
  ),
  'this' => 
  array (
    0 => 'imagick.resizeimage.php',
    1 => 'Imagick::resizeImage',
    2 => 'Scales an image',
  ),
  'up' => 
  array (
    0 => 'class.imagick.php',
    1 => 'Imagick',
  ),
  'prev' => 
  array (
    0 => 'imagick.resetimagepage.php',
    1 => 'Imagick::resetImagePage',
  ),
  'next' => 
  array (
    0 => 'imagick.rollimage.php',
    1 => 'Imagick::rollImage',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/imagick/imagick/resizeimage.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="imagick.resizeimage" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">Imagick::resizeImage</h1>
  <p class="verinfo">(PECL imagick 2, PECL imagick 3)</p><p class="refpurpose"><span class="refname">Imagick::resizeImage</span> &mdash; <span class="dc-title">Scales an image</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-imagick.resizeimage-description">
  <h3 class="title">Description</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">function</span> <span class="methodname"><strong>Imagick::resizeImage</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$columns</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$rows</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$filter</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.float.php" class="type float">float</a></span> <code class="parameter">$blur</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$bestfit</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> <code class="parameter">$legacy</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong></span></span><br>): <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span></div>

  <p class="para rdfs-comment">
   Scales an image to the desired dimensions with a
   <a href="imagick.constants.php#imagick.constants.filters" class="link">filter</a>.
  </p>
  <blockquote class="note"><p><strong class="note">Note</strong>: 
 <p class="simpara">
  The behavior of the parameter <code class="parameter">bestfit</code> changed in Imagick 3.0.0.
  Before this version given dimensions 400x400 an image of dimensions 200x150 would be
  left untouched. In Imagick 3.0.0 and later the image would be scaled up to size 400x300 as
  this is the &quot;best fit&quot; for the given dimensions. If <code class="parameter">bestfit</code>
  parameter is used both width and height must be given.
 </p>
</p></blockquote>
 </div>


 <div class="refsect1 parameters" id="refsect1-imagick.resizeimage-parameters">
  <h3 class="title">Parameters</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">columns</code></dt>
     <dd>
      <p class="para">
       Width of the image
      </p>
     </dd>
    
    
     <dt><code class="parameter">rows</code></dt>
     <dd>
      <p class="para">
       Height of the image
      </p>
     </dd>
    
    
     <dt><code class="parameter">filter</code></dt>
     <dd>
      <p class="para">
       Refer to the list of <a href="imagick.constants.php#imagick.constants.filters" class="link">filter constants</a>.
      </p>
     </dd>
    
    
     <dt><code class="parameter">blur</code></dt>
     <dd>
      <p class="para">
       The blur factor where &gt; 1 is blurry, &lt; 1 is sharp.
      </p>
     </dd>
    
    
     <dt><code class="parameter">bestfit</code></dt>
     <dd>
      <p class="simpara">
       Optional <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> parameter.
       If set to true, the image is resized to fit within the given dimensions
       while preserving the aspect ratio.
      </p>
     </dd>
    

    
    <dt><code class="parameter">legacy</code></dt>
     <dd>
      <p class="simpara">
       Optional <span class="type"><a href="language.types.boolean.php" class="type bool">bool</a></span> parameter.
       If set to true, the calculations are done with the small rounding bug that existed in
       Imagick before 3.4.0. If set to false, the calculations should produce the same results
       as the ImageMagick command-line tools.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-imagick.resizeimage-returnvalues">
  <h3 class="title">Return Values</h3>
  <p class="para">
   Returns <strong><code><a href="reserved.constants.php#constant.true">true</a></code></strong> on success.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-imagick.resizeimage-changelog">
  <h3 class="title">Changelog</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>Version</th>
      <th>Description</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>PECL imagick 2.1.0</td>
      <td>
      Added optional fit parameter. This method now supports proportional scaling.
      Pass zero as either parameter for proportional scaling.
      </td>
     </tr>

     <tr>
      <td>PECL imagick 3.4.0</td>
      <td>
       Added the <code class="parameter">legacy</code> parameter.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>




 <div class="refsect1 examples" id="refsect1-imagick.resizeimage-examples">
  <h3 class="title">Examples</h3>
  <p class="para">
    <div class="example" id="example-1">
      <p><strong>Example #1  <span class="function"><strong>Imagick::resizeImage()</strong></span></strong></p>
      <div class="example-contents">
      <div class="phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
</span><span style="color: #007700">function </span><span style="color: #0000BB">resizeImage</span><span style="color: #007700">(</span><span style="color: #0000BB">$imagePath</span><span style="color: #007700">, </span><span style="color: #0000BB">$width</span><span style="color: #007700">, </span><span style="color: #0000BB">$height</span><span style="color: #007700">, </span><span style="color: #0000BB">$filterType</span><span style="color: #007700">, </span><span style="color: #0000BB">$blur</span><span style="color: #007700">, </span><span style="color: #0000BB">$bestFit</span><span style="color: #007700">, </span><span style="color: #0000BB">$cropZoom</span><span style="color: #007700">) {
    </span><span style="color: #FF8000">//The blur factor where &gt; 1 is blurry, &lt; 1 is sharp.
    </span><span style="color: #0000BB">$imagick </span><span style="color: #007700">= new </span><span style="color: #0000BB">\Imagick</span><span style="color: #007700">(</span><span style="color: #0000BB">realpath</span><span style="color: #007700">(</span><span style="color: #0000BB">$imagePath</span><span style="color: #007700">));

    </span><span style="color: #0000BB">$imagick</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">resizeImage</span><span style="color: #007700">(</span><span style="color: #0000BB">$width</span><span style="color: #007700">, </span><span style="color: #0000BB">$height</span><span style="color: #007700">, </span><span style="color: #0000BB">$filterType</span><span style="color: #007700">, </span><span style="color: #0000BB">$blur</span><span style="color: #007700">, </span><span style="color: #0000BB">$bestFit</span><span style="color: #007700">);

    </span><span style="color: #0000BB">$cropWidth </span><span style="color: #007700">= </span><span style="color: #0000BB">$imagick</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getImageWidth</span><span style="color: #007700">();
    </span><span style="color: #0000BB">$cropHeight </span><span style="color: #007700">= </span><span style="color: #0000BB">$imagick</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getImageHeight</span><span style="color: #007700">();

    if (</span><span style="color: #0000BB">$cropZoom</span><span style="color: #007700">) {
        </span><span style="color: #0000BB">$newWidth </span><span style="color: #007700">= </span><span style="color: #0000BB">$cropWidth </span><span style="color: #007700">/ </span><span style="color: #0000BB">2</span><span style="color: #007700">;
        </span><span style="color: #0000BB">$newHeight </span><span style="color: #007700">= </span><span style="color: #0000BB">$cropHeight </span><span style="color: #007700">/ </span><span style="color: #0000BB">2</span><span style="color: #007700">;

        </span><span style="color: #0000BB">$imagick</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">cropimage</span><span style="color: #007700">(
            </span><span style="color: #0000BB">$newWidth</span><span style="color: #007700">,
            </span><span style="color: #0000BB">$newHeight</span><span style="color: #007700">,
            (</span><span style="color: #0000BB">$cropWidth </span><span style="color: #007700">- </span><span style="color: #0000BB">$newWidth</span><span style="color: #007700">) / </span><span style="color: #0000BB">2</span><span style="color: #007700">,
            (</span><span style="color: #0000BB">$cropHeight </span><span style="color: #007700">- </span><span style="color: #0000BB">$newHeight</span><span style="color: #007700">) / </span><span style="color: #0000BB">2
        </span><span style="color: #007700">);

        </span><span style="color: #0000BB">$imagick</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">scaleimage</span><span style="color: #007700">(
            </span><span style="color: #0000BB">$imagick</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getImageWidth</span><span style="color: #007700">() * </span><span style="color: #0000BB">4</span><span style="color: #007700">,
            </span><span style="color: #0000BB">$imagick</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getImageHeight</span><span style="color: #007700">() * </span><span style="color: #0000BB">4
        </span><span style="color: #007700">);
    }


    </span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-Type: image/jpg"</span><span style="color: #007700">);
    echo </span><span style="color: #0000BB">$imagick</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">getImageBlob</span><span style="color: #007700">();
}

</span><span style="color: #0000BB">?&gt;</span></code></pre></div>
      </div>

    </div>
  </p>
 </div>


</div><?php manual_footer($setup); ?>