Thanks. I re-tested it.
OK, first of all. There is a small bug in the original script.
<?php
$image_path=$_SERVER['DOCUMENT_ROOT']."/SITEADMIN/z_test/";
$image_name="test.jpg";
$thumb_path=$image_path;
$thumb_width=120;
function thumbnail($image_path,$thumb_path,$image_name,$thumb_width)
{
$src_img = imagecreatefromjpeg("$image_path/$image_name");
$origw=imagesx($src_img);
$origh=imagesy($src_img);
$new_w = $thumb_width;
$diff=$origw/$new_w;
$new_h=$new_w;
$dst_img = imagecreate($new_w,$new_h);
imagecopyresized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,imagesx($src_img),imagesy($src_img));
imagejpeg($dst_img, "$thumb_path"."/t-"."$image_name");
//imagejpeg($dst_img, "$thumb_path/thumbnail.jpg");
return true;
}
thumbnail($image_path,$thumb_path,$image_name,$thumb_width);
?>
it should be
$new_h=$origh/$diff;
Second, it does create the thumbnail. But the sample image I picked for jpg was small and too dark. The quality of the thumbnail is so poor. The thumbnail become just a black image (exactly). But I tested with some other images. It does create thumbnails but the quality is really poor.
Now my questions are:
Are there anyway to increase the quality of the thumbnails created by php image functions?
The thumbnails I created manually from photo shop. The size is 1/2, but the quality is 3 times better.
If php can only create these very poor quality but large size thumbnails, it doesn't help me very much. I may have to go back to the approach to create thumbnails offline manually.
Any advices?