Change php img resizer class to prevent upscaling/pixelating images (by adding whitespace)
<p>I'm using this php class (http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php) for creating the different sized images that my website requires.</p>

<p>I am using the <em>resizeToWidth()</em> method.</p>

<p>Everything is great except for if I'm requesting an output-width greater than the original, then the image is upscaled and pixelated to meet the dimensions.</p>

<p><em>What's the best way of,
if the image is too small,
keeping the original image and padding out the background/cavas with white space to meet required width?</em></p>

<pre><code> function resizeToWidth($width) {
  $ratio = $width / $this-&gt;getWidth();
  $height = $this-&gt;getheight() * $ratio;
  $this-&gt;resize($width,$height);}
</code></pre>

<p>calls:</p>

<pre><code> function resize($width,$height) {
  $new_image = imagecreatetruecolor($width, $height);
  imagecopyresampled($new_image, $this-&gt;image, 0, 0, 0, 0, $width, $height, $this-&gt;getWidth(), $this-&gt;getHeight());
  $this-&gt;image = $new_image; } 
</code></pre>

<p>I'm thinking i need:</p>

<ol>
<li>An if statement in the resizeToWidthStatement</li>
<li>an extra parameter ie 'pad=true' in the resize() method</li>
<li>something in the resize() method that centres the image and adds the whitespace</li>
</ol>

<p>any ideas?</p>
