views:

213

answers:

1

I need to build a PHP photo processing class, I know there are MANY that already exist to the public but I need to build one to do just what I need done and nothing extra and nothing less.

I need my class to do this...

1)
I create a new instance of my class and I pass in either a URL of a photo, or the path to a local photo being uploaded using POST form.

2)
I then need to take the main image and check it's dimensions, if it is wider the 800 pixels, I need to resize it down, if it is not wider then 800 then I just leave it

3)
We now need to build 2 different sized thumbnails from this image, if we resized the image to meet our 800 pixel requirement then we use that image to make the thumbnails from, otherwise we make our thumbnails from the original image.

4)
We then update a few a database records

Then completed.

I know this is not that difficult but I need to build this with best performance in mind, for example if a user uploads a 2mb photo, I don't want to hog up memory and keep building thumbnails from that photo if we already madea smaller image I think it should then use the smaller image to build out thumbnails from.

With all this information now, do you have any suggestions on how to do this in GD or imagemagick. If I make a method that does the thumbnails, how should I make sure it keeps using the smaller images to make other smaller images? I have looked at some existing image classes and they all are very complex and over done IMO however none do exactly this simple task.

A: 

The PHP GD library uses a resource object to represent images. You can use imagecopyresampled or imagecopyresized to resize the image.

If it has been resized, use the new resized image object for future operations, otherwise use the original resource object.

Anurag