1702228508

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](https://8designers.com/blog/bl-content/uploads/pages/d1d6f72feff040a9a81d9dc06a3b366d/Wow-gif.gif) ## 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)); ```

(0) Comments

Welcome to Chat-to.dev, a space for both novice and experienced programmers to chat about programming and share code in their posts.

About | Privacy | Terms | Donate
[2024 © Chat-to.dev]