Forum Moderators: coopster

Message Too Old, No Replies

PHP building thumbnails

can't build thumbs using PHP!

         

feralo

3:49 pm on Jun 14, 2006 (gmt 0)

10+ Year Member



I have a book on Object Oriented Programming that claims to show you how to create thumbnails in PHP- but as it turns out the thumbnail files already exist and all you are doing is altering them!

I deleted the thumnails (leaving the original image files) and the script broke! What good is that? Does anyone know of a way to really create thumbnails using PHP?

eelixduppy

4:18 pm on Jun 14, 2006 (gmt 0)



This can be done with PHP's GD library [us2.php.net]. I would start by searching webmasterworld for various thread on this topic. One example is here [webmasterworld.com] howver it may not be what you need exactly. Good luck!

mcavic

8:54 pm on Jun 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Here's an example similar to the function that I use to create jpg thumbnails:

function make_thumbnail($image, $thumb)
{
# $image is the path to the orignal image
# $thumb is the path to the thumbnail we're going to create

# Get the size of the original image

$size = getimagesize($image);
$width = $size[0];
$height = $size[1];

# Shrink it to 25%

$width = $width / 4;
$height = $height / 4;

# Read the image, resize it, and save the thumbnail

if (file_exists($thumb)) {
unlink($thumb);
}

$dst_img = ImageCreateTrueColor($width, $height);
$src_img = ImageCreateFromJpeg($image);
ImageCopyResized($dst_img, $src_img, 0, 0, 0, 0, $width, $height, ImageSX($src_img), ImageSY($src_img));

ImageJpeg($dst_img, $thumb);
}