xenon2050 Posted July 30, 2007 Share Posted July 30, 2007 I would like to write a php script that will take the pictures in a folder and display them in the way I specify. For instance, having a page with thumbnails at the bottom and a larger picture right above that, and if you click on a thumbnail it will display that picture in the larger space right above it. I could probably do this in HTML but then each picture would have to be coded in manually. I want to just be able to throw a bunch of pictures in a directory and have them display as thumbnails automatically. Does that make sense? Any ideas on how to do this? Will I need a SQL database? Quote Link to comment https://forums.phpfreaks.com/topic/62506-grab-images/ Share on other sites More sharing options...
ss32 Posted July 30, 2007 Share Posted July 30, 2007 you could do it using an SQL database, and that would probably be the preferred method considering that you can store more than just the file name as an attribute, and it makes pagination a whole lot easier. anyway, to do thumbnails you will need a php resizer script. fortunately i have one that works for JPEG files only. <?php header("Content-type: image/jpeg"); //process the desired image size //usage: showJpg.php?image=(desiredImage) $image = $_GET['image']; $size = $_GET['size']; $resample = $_GET['res']; $quality = $_GET['qual']; $src = @imagecreatefromjpeg($image); if ($src) { list($width, $height) = getimagesize($image); if ($width > $height) { $factor = ($size / $width); $newW = $size; $newH = $height * $factor; }else { $factor = ($size / $height); $newW = $width * $factor; $newH = $size; } $thumb = imagecreatetruecolor($newW, $newH); if ($resample == false) { imagecopyresized($thumb, $src, 0, 0, 0, 0, $newW, $newH, $width, $height); }else{ imagecopyresampled($thumb, $src, 0, 0, 0, 0, $newW, $newH, $width, $height); } }else{ $thumb = imagecreatetruecolor(128, 128); $clr_grey = imagecolorallocate($thumb, 64,64,64); $clr_red = imagecolorallocate($thumb, 255, 32, 0); imagefilledrectangle($thumb, 10, 10, 115, 90, $clr_grey); imagestring($thumb, 5, 35, 40, "Error_", $clr_red); } imagejpeg($thumb, '', $quality); //destroy the image imagedestroy($thumb); imagedestroy($src); ?> if you want to browse through a directory of images, this loop may help: <?php $dir = opendir("path/to/picture/library"); while (false !== ($file = readdir($dir))) { //TODO: handle files } closedir($dir); Quote Link to comment https://forums.phpfreaks.com/topic/62506-grab-images/#findComment-311116 Share on other sites More sharing options...
calabiyau Posted July 30, 2007 Share Posted July 30, 2007 http://www.alistapart.com/articles/imagegallery You will probably need some javascript as well if you want to have thumbnails that bring up photos on the same page. Quote Link to comment https://forums.phpfreaks.com/topic/62506-grab-images/#findComment-311140 Share on other sites More sharing options...
xenon2050 Posted July 31, 2007 Author Share Posted July 31, 2007 Thank you for your help. I'll hack away at it and if I have any problems I'll probably come and ask for help. If I was using javascript to bring up photos on the same page, would I write a javascipt function and call it from my php script? Sorry if that sounds thick headed I just haven't integrated javascript in my websites very much. As far as using SQL for this, does anyone have a tutorial on what i would need to do, I've looked around and couldn't find anything on what i want to do here. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/62506-grab-images/#findComment-311810 Share on other sites More sharing options...
datafan Posted July 31, 2007 Share Posted July 31, 2007 I store the images in a directory and only the image names in the database as a reference. I wonder if you didn't want to use javascript if you could make the illusion happen with a frames page by opening the images in a certain frame? Has anyone done this? Quote Link to comment https://forums.phpfreaks.com/topic/62506-grab-images/#findComment-311856 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.