try this. i'm quite a newbie too, but the code works for me. mail me if it doesn't work for you.
<pre>
<?php
simplethumbnail function by phil.
#
some comments:
#
for a given image url on your server, a thumbnail will be created. the function returns
the html code to display the created thumbnail including a link to the original file.
you need the GD lib enabled for this to work. do a phpinfo() to find out;
#
thank god for php and gdlib, but note that gdlib's resampling isn't greatest quality.
i'll soon try to do the conversion via 'exec()' of an external commandline program,
irfanview (simple, fast, great & free) is a hot candidate. any other ideas where to find a useful app for that?
echo thumbnail("images/test.jpg"); # function call, adjust the image path to fit your needs
function thumbnail($src_url) {
# split src_url to $src_path (folder which your source image is in) and $src_name (filename)
$temp_url = explode("/",$src_url);
$i=0;
while ($i < sizeof($temp_url)) {
if ($temp_url[$i] != end($temp_url)) {
@$src_path .= $temp_url[$i]."/"; # src_path
} else {
$src_name = $temp_url[$i]; #src_name
}
$i++;
}
##########################################################################
# general settings
##########################################################################
$dst_path = "thumbs/"; # if you want to put your thumbnails in an extra folder specify a dst_path here
$dst_name = "t_$src_name";
$scale = 0.2;
$quality = 80; # [0-100], 100 being max.
##########################################################################
$dst_url = $dst_path.$dst_name;
$src_size= getimagesize("$src_url");
# calculate h and w for thumb:
$dst_w=$src_size[0]*$scale;
$dst_h=$src_size[1]*$scale;
$dst_img=ImageCreate($dst_w,$dst_h);
$src_img=ImageCreateFromjpeg($src_url); #
ImageCopyResized($dst_img,$src_img,0,0,0,0,$dst_w,$dst_h,ImageSX($src_img),ImageSY($src_img)); # see www.php.net/imagecopyresized for details
imagejpeg($dst_img,$dst_url,$quality); # output the in-memory file to disk
imagedestroy($dst_img); # free memory. important if you create many images at once
$dst_size= getimagesize("$dst_url");
$src_filesize = round(filesize($src_url)/1024,2)." kB ";
$dst_filesize = round(filesize($dst_url)/1024,2)." kB ";
$thumb = "<a href=\"$src_url\"><img src=\"$dst_url\" border=\"0\" ".$dst_size[3]." /></a>";
# remove all this for prouduction use, it's only to illustrate the variable names # remember to remove the .$info from the return value
$info .= "<p><font color=\"AAAAAA\"><b>quick and dirty php thumbnail function by <a href=\"http://www.phillipoertel.com\" target=\"phil\">phillip oertel</a></b></font>\n";
$info .= "<p>\$src_path = $src_path<br />\$src_name = $src_name<br />\$src_filesize = $src_filesize<br />\n";
$info .= "Source dimensions (W x H): ".$src_size[0]." x ".$src_size[1]."\n";
$info .= "<p>\$dst_path = $dst_path<br />\$dst_name = $dst_name<br />\$dst_filesize = $dst_filesize<br />\n";
$info .= "Destination dimensions (W x H): ".$dst_size[0]." x ".$dst_size[1];
$info .= "<p> Scale = $scale<br />JPEG Quality = $quality\n";
$info .= "<p>the HTML code created:<br />\n".htmlspecialchars($thumb);
return $thumb.$info;
}
?>
</pre>