Created
October 4, 2010 02:56
-
-
Save abronte/609197 to your computer and use it in GitHub Desktop.
PHP image resize
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $image_w = imagesx($image); | |
| $image_h = imagesy($image); | |
| //figure out if we are going to resize by the width or the height | |
| //if the original image is wider than the new dimension, resize by the width | |
| // or else resize by the height | |
| if (($image_w / $image_h) >= ($new_w / $new_h)) { | |
| $h = $image_h * $new_w / $image_w; | |
| $w = $new_w; | |
| } else { | |
| $h = $new_h; | |
| $w = $image_w * $new_h / $image_h; | |
| } | |
| //create a blank image with the new calculated dimensions | |
| $tmp = imagecreatetruecolor($w, $h); | |
| //copy the original image to the new image while resizing | |
| imagecopyresampled($tmp,$image,0,0,0,0,$w,$h,$image_w,$image_h); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment