I wrote this piece of code recently in order to show thumbnails on-the-fly (using PHP) for a user uploaded gallery. It is VERY simplistic but may be ideal for those of you who want to simply show a good-looking, quick-loading thumbnail in the perfect size without spending any money or writing code.
To avoid confusion, let me say this is NOT for showing website thumbnails. It is only good for generating thumbnails of images (local or remote) on your website. To show website thumbnails on-the-fly, please join our main service for free at https://shrinktheweb.com
Here's the PHP thumbnail generator code:
<?php /************************************************************ ThumbFly: v.1-0-0 Purpose: Outputs a thumbnail image of a jpeg image file Local, Remote, or Dynamic (w/ mods) Author: Brandon Elliott URL: https://shrinktheweb.com/content/custom-sizing-php-thumbnail-generator-code-thumbfly.html ************************************************************/ $Size=$_GET['Size']; $filename=$_GET['filename']; $w=$_GET['w']; if($Size) {$filename=$filename."&Size=".$Size;} // Content type header('Content-type: image/jpeg'); // Get new dimensions list($width, $height) = getimagesize($filename); $ratio=$w/$width; $new_height = $height * $ratio; // Resample $image_p = imagecreatetruecolor($w, $new_height); $image = imagecreatefromjpeg($filename); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $w, $new_height, $width, $height); // Output imagejpeg($image_p, null, 100); ?>
To use this code, you would use:
<img src=http://www.abc.com/thumb.php?filename=path/to/file.jpg&w=width>
You will need to replace abc with your domain, the path/to/file.jpg with the relative path to the image on your server and then, you will just put in whatever width you want. For instance, I use w=150 for a 150 pixel wide thumbnail (output is proportionate to original).
Note in my example that I called the file "thumb.php."
My code is written only to support jpegs, but if you have a little PHP experience, you could easily modify it to support gif, bmp, png, etc.
I hope this is helpful to some of you!
Best regards,
Brandon