Image resize in PHP

Recently I have been working on a Content Management System for Toshiba TEC Australia. Basically we have built a recipe printer kiosk application that allows you to browse recipes, share them on social networks, email, and also to print them in-store, leveraging a serial printer installed on the kiosk.

The CMS I’ve ben working on lets you add new recipes, modify existing ones, manage categories etc.. I built it in Flex using PHP as a server-side language. Every recipe can have an image associated with it, so in my CMS I have provided a form to handle file upload, and delegated the resize of the image to PHP.

I found this great class, SimpleImage that allows you to resize and scale images, and I have added a little function to it, as I thought there was something missing:

function resizeWH($maxWidth, $maxHeight)


$currentWidth = $this->getWidth();

$currentHeight = $this->getHeight();

if($currentWidth > $currentHeight)

$this -> resizeToWidth($maxWidth);


$this -> resizeToHeight($maxHeight);


You basically specify the maximum width and height you want your image to be resized at, and the function just determines if your image has a landscape or portrait orientation, so it can resize it without changing it’s aspect ratio.