Image resize function

Using this function, you can reduce, enlarge, and change the width and height at which to display it, the way the image will appear depends entirely on the browser being used, and whether the original is resampled rather than simply pixel resized. ![resize it]( ## How It Works This recipe first looks up the image’s current width and height and places these values in the variables $oldw and $oldh. It then creates a new GD image object of the new width and height, as supplied in $w and $h, like this: ```php $oldw = imagesx($image); $oldh = imagesy($image); $temp = imagecreatetruecolor($w, $h); ``` ### the function ```php function ImageResize($image, $w, $h) { $oldw = imagesx($image); $oldh = imagesy($image); $temp = imagecreatetruecolor($w, $h); imagecopyresampled($temp, $image, 0, 0, 0, 0, $w, $h, $oldw, $oldh); return $temp; } ``` ## How to Use It The way you use this recipe is to have an image already created or loaded into a GD image object, which you then pass to the function, along with two arguments stating the new width and height needed. Once the new image has been created, it’s returned by the function. ```php $image = imagecreatefromjpeg("test.jpg"); header("Content-type: image/jpeg"); imagejpeg(ImageResize($image, 500, 100)); ```

All comments