Created
December 19, 2018 13:37
-
-
Save locvfx/04539cfd3c5b4ed44c2de851f9c95f49 to your computer and use it in GitHub Desktop.
Crop and resize image
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
| <?php | |
| // File and new size | |
| $filename = 'test.jpg'; | |
| $percent = 0.5; | |
| // Content type | |
| header('Content-Type: image/jpeg'); | |
| // Get new sizes | |
| list($width, $height) = getimagesize($filename); | |
| $newwidth = $width * $percent; | |
| $newheight = $height * $percent; | |
| // Load | |
| $thumb = imagecreatetruecolor($newwidth, $newheight); | |
| $source = imagecreatefromjpeg($filename); | |
| // Resize | |
| imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); | |
| // Output | |
| imagejpeg($thumb); | |
| ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment