- create a thumbnail of the uploaded image
- resize the image if either its width or height were over 600px and store the resized image rather than the original
- store a caption for the image in a database table
Other Handy Functions
I also included in the photo class two functions to crop photos. The first, doCenterCrop(), crops to a height and width you specify, always cropping to the center of the source image.[php] // don’t forget to include the photo class @include photo.php; // instantiate the photo class. Without a file upload, you pass // an array of info about the photo you’re going to crop. Note that // because we’re not cropping a file upload (though you could // certainly do that), the tmp_name and the name are the same. $photo = new Photo(array(‘name’=>’mydirectory/myfile’,'tmp_name=>’mydirectory/myfile’)); // we pass the width and height we want to crop to to the doCenterCrop function $width = 190; $height = 131; $photo->doCenterCrop($width,$height); [/php]
If you are feeling a little bit fussy and want to specify exactly where the photo should be cropped, you can do that with the doFullCrop() function:
$photo = new Photo(array(‘error’=>0,’name’=>’mydirectory’,'tmp_name’=>’mydirectory/myphoto’));
// this time, we’re passing the top and left coordinates, along with the final
// width and height to the doFullCrop() method.
$top = 25;
$left = 15;
$width = 120;
$height = 147;
Download the photo class.