Best php thumbnail creation script

Hi,

Which is the best free open source thumbnail creation php script for images formats such as GIF, JPG, PNG.

Please let me know.

Thanks

PHP.net have an entire ebook on how to use the GD image library which is very helpful.

http://www.php.net/manual/en/book.image.php

If you need something quick all i did was a quick Google search, click here for results

This is the code I use to generate a thumbnail off of an image, right now it’s either gif or jpeg, but you can add a png also.



<?php
    
    $fullimageurl = "http://$domain/images/$image";
    $fullimageurl2 = "http://$domain/images/noimagefound.jpg";


    $fp = fopen($fullimageurl, 'r');

    if (strpos($http_response_header[0], '200') !== false) {
    $imagesurl = $fullimageurl;
    } else {
    $imagesurl = $fullimageurl2;
    }


    $width  = 125;
    $height = 125;
    
    $extension = strrchr($imagesurl, '.');
    $extension = strtolower($extension);
    
    
    if(($extension==".jpeg")||($extension==".jpg")) {

            header('Content-type: image/jpeg');
            list($width_orig, $height_orig) = getimagesize("$imagesurl");

                if ($width && ($width_orig < $height_orig)) {
                $width = ($height / $height_orig) * $width_orig;
                } else {
                $height = ($width / $width_orig) * $height_orig;
                }

            $image_p = imagecreatetruecolor($width, $height);
            $image = imagecreatefromjpeg("$imagesurl");
            imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
            imagejpeg($image_p, null, 100);
            exit();
    }
    
    
    if(($extension==".gif")) {
    
            header('Content-type: image/gif');
            list($width_orig, $height_orig) = getimagesize("$imagesurl");

                if ($width && ($width_orig < $height_orig)) {
                $width = ($height / $height_orig) * $width_orig;
                } else {
                $height = ($width / $width_orig) * $height_orig;
                }

            $image_p = imagecreatetruecolor($width, $height);
            $image = imagecreatefromgif("$imagesurl");
            imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
            imagejpeg($image_p, null, 100);
            exit();
    
    }

    if(($extension==".png")) {

            Header('Content-Type: image/png');
            list($width_orig, $height_orig) = getimagesize("$imagesurl");

                if ($width && ($width_orig < $height_orig)) {
                $width = ($height / $height_orig) * $width_orig;
                } else {
                $height = ($width / $width_orig) * $height_orig;
                }

            $image_p = imagecreatetruecolor($width, $height);
            $image = imagecreatefrompng("$imagesurl");
            imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $width_orig, $height_orig);
            imagejpeg($image_p, null, 100);
            exit();
    
    }

?>


$fullimageurl is what I get from the database. I am sure you can use a link like :

domain.com/image/thumb?fullimageurl=image.gif or what ever then get it

$fullimageurl = $_GET[‘fullimageurl’];

Instead of the /thumb?fullimageurl=image.gif I use url_array so it becomes: /images/thumb/image.gif

to display /thumb/ instead of /thumb.php use htaccess with this code:

<Files thumb>
ForceType application/x-httpd-php
AcceptPathInfo On
</Files>

just change the thumbnail size to the size you need. Right now it’s set at 125px.

Thanks,
Kevin

I shrunk the size of my images folder tremendously. Instead of having a large image and a smaller thumbnail image, I just use the large image with this script and get a smaller one.

If anyone can spot a problem, please let me know.