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);

else

$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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s