Welcome, guest | Sign In | My Account | Store | Cart

This little script create an thumbnail from an jpeg-image. To use it, use an link in form of thumb.php?url=path_to_big_image.jpg with little changes it will create png-thumbnails.

PHP, 15 lines
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<?
    header ("Content-type: image/jpeg"); # We will create an *.jpg
    $pic = @imagecreatefromjpeg($url) or die ("Image not found!");
    if ($pic) {
        $width = imagesx($pic);
        $height = imagesy($pic);
        $twidth = 160; # width of the thumb 160 pixel
        $theight = $twidth * $height / $width; # calculate height
        $thumb = @imagecreatetruecolor ($twidth, $theight) or
	    die ("Can't create Image!");
	imagecopyresized($thumb, $pic, 0, 0, 0, 0,
	    $twidth, $theight, $width, $height); # resize image into thumb
	ImageJPEG($thumb,"",75); # Thumbnail as JPEG
    }
?>
Created by Fritz Cizmarov on Fri, 7 Mar 2003 (MIT)
PHP recipes (51)
Fritz Cizmarov's recipes (2)

Required Modules

  • (none specified)

Other Information and Tasks