Created
January 25, 2014 17:42
-
-
Save IngmarBoddington/c0fb3248d9b5e80055a0 to your computer and use it in GitHub Desktop.
Simple image resizer (requires GD)
This file contains 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 | |
//Needs injection protection / validation / extention for other image types | |
header('Content-type: image/jpeg'); | |
ini_set('memory_limit', '50M'); | |
if (isset($_GET['f'])) { | |
$file = $_GET['f']; | |
list($width, $height) = @getimagesize($file); | |
//Set new dimensions (defaults to old if no w parameter given) | |
if (isset($_GET['w'])) { | |
$newWidth = $_GET['w']; | |
$newHeight = ($newWidth * $height) / $width; | |
} else { | |
$newWidth = $width; | |
$newHeight = $height; | |
} | |
//Set new canvas and source | |
$canvas = imagecreatetruecolor($newWidth, $newHeight); | |
$source = imagecreatefromjpeg($file); | |
//Create Image | |
imagecopyresampled($canvas, $source, 0, 0, 0, 0, $newWidth, $newHeight, $width, $height); | |
imagejpeg($canvas, null, 100); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment