This is a discussion on thumbnail how to within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hi, I am looking for an easy to use thumbnail php script. I googled arround but cannot find one, or ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Message-ID: <438948b6$0$711$5fc3050@dreader2.news.tiscali.nl > from
Bruintje Beer contained the following: >Hi, > >I am looking for an easy to use thumbnail php script. I googled arround but >cannot find one, or maybe my search is not so good :) > Here's a simple one. You load your .jpg files and this script to a directory. Then you create a subdirectory called thumbs and chmod it to 777. Run the script and on the first pass it creates thumbnail images in the subdirectory. Subsequent viewings use the stored images. <HTML> <HEAD> <TITLE>Contact sheet</TITLE> <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1"> <style> ..image{width:114px;text-align:center;margin:4px} img{border: 0px; margin:auto;} </style </HEAD> <BODY BGCOLOR="#FFFFFF" TEXT="#000000"> <div style="text-align:center"> <div style="margin:auto"> <?php $path=$_SERVER['SCRIPT_FILENAME']; $dir=dirname($path); $thumbpath = "thumbs/"; $height=75; if ($dh = opendir($dir)) { while (($file = readdir($dh)) !== false) { //print $dir . $file; if($file!="." && $file!=".." && strtolower(substr($file,-3))=="jpg"){ $filepath=$thumbpath."s_".$file; if(!file_exists($filepath)){ if($src_img = @imagecreatefromjpeg($file)){ $new_h = $height; $size=getimagesize($file); $new_w = ($new_h*$size[0])/$size[1]; $dst_img = imagecreatetruecolor($new_w,$new_h); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $new_w, $new_h, $size[0], $size[1]); imagejpeg($dst_img, $filepath, 100); $alt=$file; } else{ $alt="Bad jpg!"; } } else{ $alt=$file; } echo "<span class='image'><a href=\"$file\"><img src='".$filepath."'alt='$alt'></a></span>\n"; } } closedir($dh); } ?> </div> </div> </BODY> </HTML> -- Geoff Berrow 0110001001101100010000000110 001101101011011001000110111101100111001011 100110001101101111001011100111010101101011 |