ColdFusion Auto Gallery

Posted By: Mark Aplet 12 Comments September 06, 2008

Creating a photo gallery can be time consuming for even a handful of images. Auto Gallery is a quick and dirty photo gallery tag meant to solve one problem. Automatically generating photo galleries from a folder of images and thumbnails. Team up autoGallery with Photoshop's Batch automation tools and you have a very quick gallery of images!

If your the type of person that just can't wait, here is a demo and download link.

View Demo | Download Zip

Preparing Your Images

Prepare your images by creating a large version and a thumbnail version. The thumbnails can be any size you like. It's best to make them no larger than 100 pixels on either side if unless you do not mind changing the css. Large images can be any size you wish.

Save the thumbnails into a separate folder (thumbs) from your large images (large) but keep the file names the same. autoGallery simply references the large images based on your thumbnail file name.

For sake of demonstration I am placing the both the "thumbs" and "large" folder in a folder called images. This is the default directory for autoGallery. You can think of this as an album. The name can be anything you want. Naming it something other than "images" just means that you will need to use the image path attribute in the call to the tag. See Optional Attributes below.

Preparing Your Document

autoGallery uses jquery and FancyBox for it's cool gallery overlay effect. You can use anything you like with minimal customization. For this we will a few lines to our document <head> and call our magical jquery code. While we are there, we will call the fancy zoom css file and our page styles.

<link rel="stylesheet" type="text/css" href="resources/style.css" />
<link rel="stylesheet" type="text/css" href="resources/fancy.css" />
<script type="text/javascript" src="js/jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="js/jquery.fancybox-1.0.0.js"></script>
<script type="text/javascript">
   $(function(){
      $(".thumbnails").fancybox({ 'zoomSpeedIn': 500, 'zoomSpeedOut': 500, 'overlayShow': true });
   });
</script></p>

Using the Tag

You can use autoGallery with any existing coldfusion page with any style you wish. I have included a starter index.cfm for you to use. There is only one line needed to call the autoGallery tag.

<cfmodule template="autoGallery.cfm">

Place this module call on any page that you wish to use autoGallery with and that's it.

Optional Attributes

You can specify additional parameters to the tag for adding various functionality or customization. Here is a list of optional attributes.

Attribute Required Default
largeimagepath Only if default is not used images/large/
smallimagepath Only if default is not used images/thumbs/
classvalue no thumbnails
sort no file name
order no asc
showtitle no false

largeimagepath: Path to large images folder

smallimagepath: Path to small images folder

classvalue: If you need to specify a different class for the thumbnails in case it conflicts with existing page styles.

sort: Change sorting method to any of the following attributes: name, size, type, dateLastModified

order: Sort in asc or decs order

That's all there is to it. I think it took longer to write this article than it took to create. This is by far my most used snippet of code. It enables me to put images online in record time for clients, friends, and family to enjoy. Best of all, it looks great, and is incredibly easy to use.

Additional Credits

Though I have used this script for several years, I do need to give credit to Script Style for publishing their php auto gallery script. After reading their article and seeing the number of positive comments they received, I decided that I could make my script available to the community as well. I did however, ditch my old lightbox script in favor of the jquery script because it looks way cooler than lightbox.

Tags: ColdFusion · Design · Freebies

12 comments so far ↓

  • 1 Andy Ford // Sep 7, 2008 at 9:19 PM
    I haven't seen your photography before... freaking amazing!
  • 2 Mark Aplet // Sep 8, 2008 at 11:31 AM
    Thanks Andy :) I hope to have a photography section soon on this site soon. I also want to start posting more creative type posts and leave some of the tech alone for a while. If you like those photos stand by for even better ones coming soon. :)
  • 3 Olivia // Sep 29, 2008 at 10:42 AM
    Wonderful script and beautiful photography!! Now i just have one question - Is there any way to add captions to the photos? I wish I could figure it out on my own but I've spent too much time and have to give up. If you have the time to answer I'd appreciate your expertise. thank you so much
  • 4 Mark Aplet // Sep 29, 2008 at 11:08 AM
    Thanks Olivia, The caption is controlled by the showtitle value. It's either yes or no. Setting it to no (the default) will not show the image name as a caption. You cannot have a dynamically generated gallery of images from a folder unless your using another application that could get the title or description from the EXIF information. Coldfusion 8 does support EXIF and IPTC with the cfimage tag. For more info I suggest reading Seth Duffy's blog http://www.leavethatthingalone.com/blog/index.cfm/2007/7/18/ColdFusion8_Exif_and_IPTC as he walks you through how to add that. It might be a lot of overhead for a large gallery of images, but that my not be a concern if you have the resources. If I can find some time this week I will add that to this script and offer it up as an option for those on CF 8. Hope this helps.
  • 5 Olivia // Sep 29, 2008 at 1:48 PM
    Thank you so much for the feedback. In reading Duffy's blog I'm going to see if I can add a headline to each photo in Adobe Bridge and then try to call the "headline" IPTC Metadata with the code he provided. If that doesn't work, I guess I can always manually add the caption in photoshop.
    Maybe I should just be patient and let you take a look :)
    Thanks for being there for us beginners in coldfusion! I'm ever so grateful
  • 6 Mark Aplet // Sep 29, 2008 at 2:45 PM
    Bridge will add the appropriate IPTC data without an issue. One thing to consider, and it's up to you really. However the stock photo industry as well as Other programs like iPhoto, Aperture, Lightroom use title, description, and keywords almost as a standard. You may wish to use those fields when populating your images IPTC data. It may be a best practice for future proofing your efforts.
  • 7 Marita Hines // Oct 15, 2008 at 8:13 PM
    I love this gallery! It works so smooth. Is there any way to change the number across or the amount of space (width) it take up?
  • 8 Mark Aplet // Oct 15, 2008 at 8:34 PM
    @Marit, Because images are inline elements they will naturally float to the left. As a result, you can control how many images display in a row just by making the container they are contained within larger or smaller. When I use it for clients, I typically don't set a limit so that the images expand to fill the entire screen. The user can enlarge or shrink their browser so that it looks best for them. Hope this makes sense.
  • 9 John Gag // Mar 24, 2009 at 6:45 PM
    I am going to have to take a look at this. Thanks Mark!
  • 10 John Gag // Mar 24, 2009 at 7:07 PM
    Ok, played with it for 10 min. Great stuff as always mark!!
  • 11 Ed Sun // Apr 24, 2009 at 12:17 AM
    I think this is great, thanks!

    I am having problem "containing" the gallery (same as Marita above). I am just creating an HTML table with a fixed width but the gallery keeps stretching the table larger. Need help.


    Tks
  • 12 Mark Aplet // Apr 24, 2009 at 10:53 AM
    If your trying to insert images into cells, then you will have to brake the rows/cols using your own coldfusion scripts. e.g. cfloop. If it's just a single celled table then it's probably some css code that is causing the conflict. My not so helpful answer would be DON"T USE TABLES. Yuck! Sorry, I couldn't help myself. But I am a bit of a snob about using tables for what they were created for.

Leave a Comment

Leave this field empty:

Theme Design By Mark Aplet

Super Powered by Mango Blog

draw-trap