Schlo_50 Posted February 26, 2007 Share Posted February 26, 2007 I need to have page of items displayed as thumbnails which when clicked, go to another page which then shows the items details. I have a database and am currently storing the full size images URL's instead of the actual image. All i need now is the code the display the images as scaled down thumbnails when the URL stored in my database is called. Anyone got some examples? Quote Link to comment Share on other sites More sharing options...
bobleny Posted February 26, 2007 Share Posted February 26, 2007 Ever consider HTML? <a href="link.ext"><img src="thumb.ext" border="0" width="20" height="30"></a> Or if you wanted to echo it echo "<a href='link.ext'><img src='thumb.ext' border='0' width='20' height='30'></a>"; Quote Link to comment Share on other sites More sharing options...
mbtaylor Posted February 26, 2007 Share Posted February 26, 2007 Create a php page e.g image.php and insert this code: <? $pic = $_GET['pic']; $width = $_GET['width']; if (strstr ($pic, "jpg")){ $im = imagecreatefromjpeg($pic); }else{ $im = imagecreatefromgif($pic); } $px = (imagesx($im) - 7.5 * strlen($string)) / 2; $old_x=imageSX($im); $old_y=imageSY($im); $new_w=(int)($width); if (($new_w<=0) or ($new_w>$old_x)) { $new_w=$old_x; } $new_h=($old_x*($new_w/$old_x)); $thumb_w=$new_w; $thumb_h=$old_y*($new_h/$old_x); $thumb=ImageCreateTrueColor($thumb_w,$thumb_h); imagecopyresampled($thumb,$im,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); imagejpeg($thumb,"",90); imagedestroy($thumb); header("Content-type: image/jpeg"); ?> You can then resize images like: http://mywebsites/image.php?pic=images/somepic.jpg&width=130 Added: This requires the GD library compiled into PHP Quote Link to comment Share on other sites More sharing options...
tarun Posted February 26, 2007 Share Posted February 26, 2007 Ever consider HTML? <a href="link.ext"><img src="thumb.ext" border="0" width="20" height="30"></a> Or if you wanted to echo it echo "<a href='link.ext'><img src='thumb.ext' border='0' width='20' height='30'></a>"; I Think He Meant How To Create A Thumbnail Image Of A File Using PHP... Quote Link to comment Share on other sites More sharing options...
bobleny Posted February 26, 2007 Share Posted February 26, 2007 Ever consider HTML? <a href="link.ext"><img src="thumb.ext" border="0" width="20" height="30"></a> Or if you wanted to echo it echo "<a href='link.ext'><img src='thumb.ext' border='0' width='20' height='30'></a>"; I Think He Meant How To Create A Thumbnail Image Of A File Using PHP... Could be, but he never specified. What ever gets the job done! Why is there "[/url]" in my post!? I never typed that.... :-\ Quote Link to comment Share on other sites More sharing options...
Schlo_50 Posted February 28, 2007 Author Share Posted February 28, 2007 { echo $row['st_id']. ' - ' . $row<img src=['image'] border='0' width='20' height='30'>' . '$row['descr'] . ' - ' . $row['price'] . "<br />\n"; } Will this not work then? I haven't actually stored the images in the database, just their URL's. Quote Link to comment Share on other sites More sharing options...
TRI0N Posted February 28, 2007 Share Posted February 28, 2007 Working with resize of an actual image can really mess with the aspect of it. If you just set the width to 20 then it will keep the aspect of them all at 20 while some may be a differnt height but will make the image dispalyed looking nicer not warped. Creating thumbnails is a better approach since becasue you are resizing the orginal image it is loading the full size of that file for display. So having some odd 100 images you are now making users download 3 MB in images just to have them resized for viewing. While you could have that same 100 images in thumbs and only be sending less then 1 MB of images to download. Quote Link to comment Share on other sites More sharing options...
mbtaylor Posted March 1, 2007 Share Posted March 1, 2007 * sigh * Quote Link to comment Share on other sites More sharing options...
tarun Posted March 1, 2007 Share Posted March 1, 2007 Right Ive Found Both Of These (Both Are Untested By Me) 1. <? //calculate thumb size $ow = imagesx($im); $oh = imagesy($im); $maxh = 100; $maxw = 150; $new_h = $oh; $new_w = $ow; if($oh > $maxh || $ow > $maxw){ $new_h = ($oh > $ow) ? $maxh : $oh*($maxw/$ow); $new_w = $new_h/$oh*$ow; } //create dst image $dst_img = ImageCreateTrueColor($new_w,$new_h); //resize and copy image ImageCopyResized($dst_img, $im, 0,0,0,0, $new_w, $new_h, ImageSX($im), ImageSY($im)); $function_image_new($dst_img,$galdir.$file); ?> <?php $file = "test.txt"; //FILEADDRESS $size = "100"; //IMAGE SIZE $data = file($file); $im = @ imagecreate($size, $size) or die(); $bc = imagecolorallocate($im, 255, 255, 255); $tc = imagecolorallocate($im, 0, 0, 0); $lines = (int) $size / 10; for ($t = 0; $t < $lines; $t++) { imagestring($im, 3, 4, 4, $data[$t], $tc); imagestring($im, 3, 4, 4 + ($t * 10), $data[$t], $tc); } header("Content-type: image/png"); imagepng($im); imagedestroy($im); ?> Thnx, Tarun Quote Link to comment Share on other sites More sharing options...
craygo Posted March 1, 2007 Share Posted March 1, 2007 Try this out http://www.phpfreaks.com/forums/index.php/topic,128054.msg535051.html#msg535051 Ray Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.