/ Published in: PHP
Expand |
Embed | Plain Text
<?php function shutdown() { if($orig_image) { imagedestroy($orig_image); } if($cropped_image) { imagedestroy($cropped_image); } if($resized_image) { imagedestroy($resized_image); } } if(($_GET['width'] / $_GET['height']) > ($old_width / $old_height)) { $new_width = $_GET['width']; $new_height = $old_height * ($_GET['width'] / $old_width); } else { $new_width = $old_width * ($_GET['height'] / $old_height); $new_height = $_GET['height']; } $resized_image = imagecreatetruecolor($new_width, $new_height); $orig_image = imagecreatefromgif("./". $_GET['image']); imagecopyresampled($resized_image, $orig_image, 0, 0, 0, 0, $new_width, $new_height, $old_width, $old_height); $cropped_image = imagecreatetruecolor($_GET['width'], $_GET['height']); imagecopy($cropped_image, $resized_image, 0, 0, 0, 0, imagesx($resized_image), imagesy($resized_image)); $black = imagecolorallocate($cropped_image, 0, 0, 0); imagerectangle($cropped_image, 0, 0, $_GET['width'] - 1, $_GET['height'] - 1, $black); imagepng($cropped_image); ?> To create a thumbnail with it: <img src="path/to/thumbnailer.php?image=image.gif&width=50&height=50" alt="" />
You need to login to post a comment.
