Revision: 1546
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at October 19, 2006 10:37 by deadmoon
Initial Code
<?php function shutdown() { global $orig_image, $cropped_image, $resized_image; if($orig_image) { imagedestroy($orig_image); } if($cropped_image) { imagedestroy($cropped_image); } if($resized_image) { imagedestroy($resized_image); } } register_shutdown_function("shutdown"); list($old_width, $old_height) = getimagesize("./". $_GET['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); header("Content-type: image/png"); imagepng($cropped_image); ?> To create a thumbnail with it: <img src="path/to/thumbnailer.php?image=image.gif&width=50&height=50" alt="" />
Initial URL
Initial Description
Initial Title
make tumbnails on the fly
Initial Tags
Initial Language
PHP