A Web Design Community curated by Chris Coyier

#64: Building a Photo Gallery

By: Chris Coyier on: 6/9/2009 with 53 Comments

This photo gallery will automatically build itself from a directory of images, including sub-directories and the images inside them. Images open in a nice looking jQuery lightbox.

Links from Video:

Running Time: 23:10

Direct Download: High Quality, Quicktime .M4V Format (AppleTV Ready)

53 Responses

  1. Michae says:

    I have been working on doing something with photo galleries for the last few days. Amazing how you always seem to make one of these as I am trying to wrap my head around it.

  2. Frank says:

    Very nice screencast. :)

    I got one suggestion. You don’t have to edit the class to add an rel attribute you can just point the lightbox to “.img-thumbnail a” like this:

    $(document).ready(function(){
    $(“.img-thumbnail a”).prettyPhoto();
    });

    • Yeah definitely, I should have mentioned that, but I also wanted to show that the class isn’t something to be afraid of but can be edited as needed to accomplish certain things. For example, I didn’t show it but I added that “GALLERY: ” text prefix to the thumbnail regions that represent a gallery not a single photo.

      • Frank says:

        Oh I see, good one, but be sure to make notes of you changes because I’m not going to make a detailed upgrade guide when I release a new version. ;)

  3. Tenzin says:

    Hi Chris!

    A great video again! There are many web gurus around but you are among the few who never hesitate to share your skills, that’s too for free. Thanks for your kind heart!

    I am wondering how one can put in into wordpress? I am kinda new with wordpress but I am doing great with everything on wordpress. I am using wordpress as CMS for a website and I would like to use the above photo gallery shown in the video.

    Can I upload photos and write captions from wordpress admin for a photo this very photogallery?

  4. Murray says:

    Excellent!

    Perfect timing as well Chris.

    Just this weekend my friends dad wanted to put together a photography website, this should help a ton.

  5. Tim Wright says:

    Did you come across an option to deal with the alt attribute it’s outputting? Looks like the cached file name or something.

  6. Helen says:

    I create one html-document per photo. That’s why my photos are no. 1 in the Google picture index.

  7. Chad says:

    Nice tutorial. For those wanting an image gallery on their own server quickly, take a look at Gallery 3, http://gallery.mentalto.com
    PHP + MySQL + jQuery. Easy to extend and theme.

  8. Jorge says:

    thank you very much for this tutorial but buenisimo, no me funsiona plugin lightbox is not that I do not know if you can help me?

  9. Beau says:

    Great Screencast. However I was wondering how you could go about displaying some sort of title or name instead of the date for each image? Cheers

    • Beau says:

      On second thoughts is it possible to display the file name under the date in Gallery view and use PHP or JS to remove the extension. Let me know if and how this can be done?

  10. Bob Hay says:

    Very good. I’ve been working on galleries lately, so this is very apropos to my interests. I’ve been watching a lot of your tutorials lately, and I must say this one is the most _accelleralted_ one I’ve seen yet. Sniff. Thanks.

  11. Bob Hay says:

    I’ll watch it again tomorrow and figure it out

  12. pregger says:

    it is my first time here to visit you site and i just felt in love with it already.
    There are very nice and useful. I love your site Chris… big hug and big thank you …

  13. TeMc says:

    This is a huge improvement – untill now I usually uploaded a folder with images, used an Automator script to generate square cropped thumbnails, upload those, use a WordPress-page-template, copy paste the WP-Lightbox code a bunch of times and copy and paste all the URLs. That sure didn’t motivate to “just put an extra” gallery in when I feel like it.

    So… two questions remaining – and I’ll be in love:

    1. How can I include the header from my theme into this and/or include this into a WordPress-page.
    2. How can I let it generate square cropped thumbnails ?

    • Frank says:

      1. Take a look in the example index.php file. You can use that code to integrate it into your website. I haven’t tried it with WordPress, but it should be possible.

      2. The class currently only resizes image. I haven’t made a crop function yet.

  14. hehe says:

    Could you please upload it YouTube? It’s really very hard watch on slow internet connection. ‘m pretty sure many people are this type of problem, so it would be helpful for them too.

    What do you think?

  15. adai says:

    I come here almost every day!It is good blog.Thinks!
    it’s do very good.but it doesn’t support Chinese well when I use it .if the the file name is Chinese it can’t be figure out correctly.hope for you answer.

  16. adai says:

    So many mistakes the comment is! I am sorry!

  17. Happy to see prettyPhoto featured into this screencast.

    Also, thanks for the layout bug, wasn’t aware of it ;)

  18. Lito says:

    Just in time. Started working on a gallery last week. This will help a lot!

  19. jozue06 says:

    Parse error: syntax error, unexpected ‘=’, expecting T_STRING in …/inc/imgbrowz0r.php on line 35

    all i get is this :(

  20. Lisa says:

    now if there was a way to adapt this so you could use a flickr gallery, I’d be right as rain

  21. Carlos says:

    I like the gallery demo, but why does the player not work on Windows platform. I use Mac at home but at work I get to learn stuff but we are using Windows platform. Is there something with the encoding of the player or what is going on?

  22. Carlos says:

    The Flash movie player I mean doesn’t work on windows

  23. Sathish says:

    I must say. Absolutely perfect timing. My friends gonna come over today evening to talk about his photography gallery site.

  24. Oscar says:

    Grate job, i love your tutorials they are awesome, it help us newbie to set us up to the the correct path in CSS and other web technologies.

  25. patte says:

    I’m fiddling the navigation and trying to give the pagination links custom images like Chris has done it.

    In the generate breadcrumps section I’ve added a ” ” around the a href tag right (in line 266) before the first (original) img-breadcrumbs div+span.

    So far this does the job and displays my to link-images but in the browser… they are not align in one line like in Chris’s Example, the next navigation element is positioned right under the home nav button and they are overlapping. If tried to align and float them but my php knowledge isn’t that superior. Seems like I can’t find the right piece of code to modify this :(

    http://i.uaarg.de/pictures/imgbrowz0r-nav-img.png

    Is anybody willing to help me?

  26. Nic Brownlee says:

    Would love to use this but am struggling with the $config = array Directory settings: Have used:
    ‘images_dir’ => dirname{__FILE__}.’/gallery’,
    ‘cache_dir’ => dirname{__FILE__}.’/cache’,
    But still no joy, sorry, I suck at PHP, any help appreciated.

    • patte says:

      Do have created both folders in the root?
      In Chris’ example there is a images folder (not relevant for
      the Gallery to work – it’s only for img files you are using in
      your css design), the gallery folder (put all your picture album
      folders in here) and the cache folder.

      So, the only thing you have to do is, not to mix up the images
      with the gallery folder. So far it’s looking fine to me.

  27. patte says:

    ah… found it… exchange your curly braces with normal ones.

    ‘images_dir’ => dirname(__FILE__).’/gallery’,
    ‘cache_dir’ => dirname(__FILE__).’/cache’,

  28. ottmar says:

    thanks for the tut.

    when I upload my Image Folders I first have to convert all
    the Umlaute [german, french stress marks, etc].

    I know this could be handled server from the server site…
    but I’m too untalented to implement it :(

    any ideas?

  29. Ryan says:

    I love this.. maybe you could do something with a multiple file up loader that has a progress bar and can select the Dir you want to upload?? Thanks for taking the time to do these screen casts there great.

  30. ratandeep bansal says:

    Hi
    I was working on a project and had to make a good looking photo-gallery. This Screen-cast has been a great help and an inspiration to make what I wanted to.

    Keep up such good work…

  31. Darren says:

    Hi,

    Looks like it works differently in FireFox than IE (as most things do).

    If I add an image say 1280 x 1024 (or any large image) FireFox will display the image using “lightbox” very nicely and at a reasonable size, without me having to change the size of the image. But IE will display the image (using “lightbox”) at its correct size which opens up very large in the browser.

    Love the gallery though!

  32. TeMc says:

    Okay, check here for a solution to get this wonderfull Imgbrowz0r to work inside of WordPress.

    http://css-tricks.com/forums/viewtopic.php?f=6&t=3077

    Just a few lines changing to get it work perfect in WordPress.

    Including full explaination and a zip-file download to a working version.

    Concept: Install Imgbrowz0r, make a page-template, and by means of a custum-field you choose what gallery to include in your page.

  33. Naomi says:

    This is brilliant. Again Chris you’ve helped me build something pretty.

  34. Suzi says:

    I watched some of your tutorials- they are all great. I really started as beginner but its getting every day better. For me homepage (which isn’t online yet) it would be great to male up a photo gallery too.
    I was trying to play a little bit around with this one here. But sorry for that silly question:
    How can a make that up without having a website online? I just want to run it on my pc!
    Thanks for help

This comment thread is closed. If you have important information to share, you can always contact me.

* This website may or may not contain any actual CSS or Tricks.