Forum •
PHP Tutorials • Create thumbnails for large images
|
Access: Admin
Total posts: 174
Status: Offline
| |
|
Create thumbnails for large images
|
|
This is the same method I've used to automatically create thumbnails for large images on the forum
PHP Code:
<?php $filename = $_GET['file']; $percent = 0.2; $font = "arial"; $fontsize = 7; header('Content-type: image/jpeg'); list($width, $height) = getimagesize($filename); $new_width = $width * $percent; $new_height = $height * $percent; $image_p = imagecreatetruecolor($new_width + 2, $new_height + 20);
$backgroundcolor = imagecolorallocate($image_p,5,90,177); $background = imagefill($image_p,0,0,$backgroundcolor); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 1, 1, 0, 0, $new_width, $new_height, $width, $height); $tcolor = imagecolorallocate($image_p,255,255,255); $t = "CLICK TO ENLARGE " . $width . "x" . $height; $fontwidth = imagettfbbox($fontsize,0,$font,$t); $g = abs($fontwidth[1]) + abs($fontwidth[2]);
imagettftext($image_p,$fontsize,0,$new_width / 2 - ($g / 2),$new_height + 14,$tcolor,$font,$t); imagejpeg($image_p, null, 100); ?>
Example:

Basically what it does is reduces any image passed to it to 20% of its original size, adds a small border and a gap at the bottom where it says CLICK TO ENLARGE and specifies the original size of the image
|
| 04:04pm 8th Oct 06
| _______________ Chris - Network-13 Last edited by Chris at 08:02am 9th Oct 06 |