Solved

Does anyone have a script or can point to one that will produce an image gallery like this?

Posted on 2003-10-31
12
201 Views
Last Modified: 2006-11-17
Hi there,

I need to add an image gallery to my site, but I need one where I can upload the images (thumb & larger) and then produc a horizontal looped gallery similar to the one on this site: http://www.simplebits.com/photos/ 

I don't need anything fancy, just to show all the thumbnails and when you click on an image it shows you a larger version. I don't need slideshows.

Can anyone help or point to a script that can do this?

Thanks
Myraa
0
Comment
Question by:Myraa
  • 6
  • 3
12 Comments
 
LVL 3

Accepted Solution

by:
red010knight earned 113 total points
ID: 9657873
The code is rather straightforward. And made even easier through the use of a database.
You just need to set up a table of data, whether it is in your php code like:
 pic1_thumb="filename_thrmb.jpg";
 pic1_Norm="filename_Norm.jpg";
 ....

or in your database with fields picID, thumbFile, normFile;
Optional fields are: displayOrder and altText(recommended)

Then in your php,
you would either use a database call to get the data, then echo it back with:
$loopCount=0;
$displayPics="<tr>";
while($images=$mysql_fetch_array($result_Pics){
  $loopCount=$loopCount+1;
  if($loopCount%6=0){  //You may want to change the number to be based on img sizes.
    $displayPics="</tr><tr>";
  }
  $displayPics.="<td><a href=/"".$images["normFile"]."/">";
  $displayPics.="<img src=/"".$images["thumbfile"]."/" alt=/"".$images["alt"]."/">";
  $displayPics.="</a></td>"
}
$displayPics.="</tr>";

if you did it declaring everything in file, you would need to ensure a naming convention and keep all files in the same place. So the loop would be basically the same
  $altRef="$pic".$loopCount."_Alt";
  $displayPics.="<td><a href=/"pic".$loopCount."_Norm.jpg/">";
  $displayPics.="<img src=/"pic".$loopCount."_Thumb.jpg/" alt=/"".$altRef."/">";
  $displayPics.="</a></td>"

That should do the trick,
Hope it helps and happy coding!
Red010Knight
0
 

Author Comment

by:Myraa
ID: 9658262
Hi there Red010Knight,

That sounds great :) - I think a non-database version would be preferable for this page of mine. Is there a way to do it so that all I have to do is have a folder on ther server and just add the images to that and then drop the PHP file in the folder also and call it like this:

<img src="http://www.domain.com/path/to/gallery.php" " title="[Rotating Images.]"  />

or is that too simplisic a view? :)

Thanks
Myraa
0
 
LVL 3

Expert Comment

by:red010knight
ID: 9658354
I think you should be able to call it that way.

And since you are doing the file name convention, you may also want to throw in a if(file_exists('filename')) and then do the diplayPics code. Else you could end up with blank images if you ever decide you do not want those images again.

And use a for loop rather than a while. With a $TOTALPICS=30+1; or whatever that is set at the bottom of your infile list of images. Or you could set all the pictures in a multidimensional array and just have sizeof(array) in your for loop.

There are a number of ways you can do it so I don't know which would be more efficient for you. The array would probably be easier to work with now that I think about it. But you would still have to pay attention to your naming conventions.

Just note that the --title="[Rotating Images.]"  -- may be misleading since its not a slideshow or a random file system or anything like that.

Hope the code -treats- you well as you finialize it and doesn't get -tricky- (sorry for the pun but being the day I couldn't resist)
Red010Knight
0
 

Author Comment

by:Myraa
ID: 9658564
Ha ha, Happy Halloween :)

Now that array sounds like a plan! - as a matter of interest (not sure if I am allowed to ask this here) - but if I asked you to do this script - Firstly, would you? and if so how much would it cost?

Myraa
0
 
LVL 3

Expert Comment

by:red010knight
ID: 9660566
Well I would prefer not to talk about this matter in the board.
And I would not mind writing the code. The only question comes to what is your deadline for it?
Email me with your deadline. number of pictures you will need to set up, and where this will be posted.
And I will get back to you the next chance I get.

you can contact me at: red010knight@hotmail.com
(NOTE for MODERATORS please give a chance for Myraa to obtain my email before removing it - Thank you)

Red010Knight
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:Myraa
ID: 9660766
I understand that - I now have the info so if you need to delete then please do.

Thanks
0
 
LVL 3

Expert Comment

by:red010knight
ID: 9662887
Myraa have you sent the email or know when you might send it to me?

Red010Knight
0
 
LVL 1

Assisted Solution

by:paStiSSet
paStiSSet earned 112 total points
ID: 9671357
how about this:

<?
echo "<table><tr>";
$dir=opendir('images/.');
$cols=-2;
while ($file = readdir($dir)) {
if (($file != ".") && ($file != ".."))
echo "<td><a href=".$file."><img src=images/". $file ." target=self><br>". $file ."</img></a></td>";
$cols=$cols + 1;
if ($cols >= 4) {
echo "</tr><tr>";
$cols=0;
}
}
echo "</tr></table>";
closedir($dir);
?>

this will do a thumbnails with the images of /images dir
0
 
LVL 3

Expert Comment

by:red010knight
ID: 9671824
Actually using the same file for thumbnails as you do for the large file is very bad code. Don't believe me try it with files that are 600X450 and use a dial up connection and measure the time to load then do the same thing with out tables and with image file resolutions of 100X75 - and then see how long it takes for the page to have all the images.

But yes that way was better - I haven't used that method before. But in this case you would need two directories - 1 that was thumbImages and the other for images, and the code would generically work. Just find a way not to use tables because some browsers will not display one table field until every element of all the fields are loaded up. Which on large tables with lots of images could take excess of 5 minutes on a dial up connection.

Red010Knight
0
 
LVL 3

Expert Comment

by:red010knight
ID: 9671880
Oh and you also reduce your ability to add ALT tags which for the user friendly versions of text browsers such as: cellphones, pdas and so forth - which is starting to be a big thing in the marketplace today as internet governing laws are coming more and more prevelant. As not designing sites for such things is potentially discriminating and so forth.

(I know not of the details of how that is panning out but I know that it is in the internet winds of control and governing of content)

Red010Knight
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now