Hi All,
I got the thumbnail scripts from Loris here,
http://www.phpbuilder.com/annotate/message.php3?id=1013332
and it work GREAT !!! except that, now my page is acting strangely...
When i first call the page for the first time, i will get broken thumbnail images. But if you HIT refresh, the thumbnail image appears again....
Here is the source codes
$conn = connect_db();
mysql_select_db($database, $conn);
$sql = "SELECT * FROM ads_images WHERE ads_image_id=".$_GET["iid"];
$result = mysql_query ($sql, $conn);
if (mysql_num_rows ($result)>0) {
$row = @mysql_fetch_array ($result);
$id = $row["ads_image_id"];
$type = $row["ads_image_type"];
$name = $row["ads_image_name"];
$data = $row["ads_image"];
}
// the temp file's extension changes wether it's a jpeg or png
switch ($type) {
case $type="image/jpeg":
$temp="temp/temp_$id.jpg";
$src=imagecreatefromjpeg($temp);
break;
case $type="image/gif":
$temp="temp/temp_$id.gif";
$src=imagecreatefromgif($temp);
break;
case $type="image/png":
$temp="temp/temp_$id.png";
$src=imagecreatefrompng($temp);
break;
default:
$temp="temp/temp_$id.jpg";
$src=imagecreatefromjpeg($temp);
}
// write to a temp file the image in order to imagecreate it from jpeg,png,gif
if (!$file=fopen($temp,"w")) return TRUE;
fwrite($file,$data);
fclose($file);
Header("Content-type: $type");
$w_src = imagesx($src); // source image width
$h_src = imagesy($src); // source image height
if (!$w) { $w = ($h/$h_src)*$w_src; } // calculate thumbnail width, given its height
if (!$h) { $h = ($w/$w_src)*$h_src; } // calculate thumbnail height, given its width
$img = imagecreatetruecolor($w,$h); // i use imagecreatetruecolor to keep a high quality img
imagecopyresampled($img,$src,0,0,0,0,$w,$h,$w_src,$h_src);
imagejpeg($img,'',85); // the third param. represents the thumbnail quality from 1 to 100
unlink($file);
unset($sql);
unset($temp);
imagedestroy($img);
imagedestroy($src);
mysql_free_result($result);
mysql_close($db);
?>
I am calling this function in another page...
Please take a look here..
http://www.1800-cars-for-sale.com/staging/kl/detail3.php?did=47
Notice the first time, you may encounter a broken image, HIT refresh...u will see the image download again...
OR is it just CACHE ??? i try with other pc is still the same problem.
Hope someone can help....
thks alot !!!
Pacochin