PDA

View Full Version : PHP and Image File Scaling



tako4
05-30-2006, 03:43 PM
The BlueHost control panel contains a nice little utility for scaling image files under Image Manager -> Image Scaler.

I'm looking for a simple way to perform that same function from the PHP script that I use to upload user image files. The general idea is to automatically scale the user's image file to a predetermined size during the upload and move_uploaded_file() process. All files are in JPG format.

Anyone know of a simple way to do this using the standard BlueHost PHP environment? Seems like this would be a fairly common requirement for any site that allows user image file uploads.

doc
05-30-2006, 06:20 PM
Check out the imagecopyresized function (http://www.php.net/manual/en/function.imagecopyresized.php) at php.net. Example 1 covers just about all you will need.

tako4
05-30-2006, 08:42 PM
Thanks Doc - that's exactly what I needed! I'm up and running.

I don't know how I missed imagecopyresized() in the manual - I guess I was looking for something like imageresizexxx().

One interesting side note - imagecopyresized() seems to give me a better quality image than imagecopyresampled(), which is not what I would have expected. In any event - problem solved!