Hi, 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.
I am using the resizeToWidth() method.
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.
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?
function resizeToWidth($width) {
$ratio = $width / $this->getWidth();
$height = $this->getheight() * $ratio;
$this->resize($width,$height);}
calls:
function resize($width,$height) {
$new_image = imagecreatetruecolor($width, $height);
imagecopyresampled($new_image, $this->image, 0, 0, 0, 0, $width, $height, $this->getWidth(), $this->getHeight());
$this->image = $new_image; }
I'm thinking i need:
- An if statement in the resizeToWidthStatement
- an extra parameter ie 'pad=true' in the resize() method
- something in the resize() method that centres the image and adds the whitespace
any ideas?