Ruby script to generate a photo gallery in Jekyll
Ruby
Switch branches/tags
Nothing to show
Latest commit 6ede340 Jan 1, 2013 @getfol getfol added Example section
Permalink
Failed to load latest commit information.
_layouts First release Jan 1, 2013
gallery_1 First release Jan 1, 2013
.gitignore First release Jan 1, 2013
LICENSE.txt First release Jan 1, 2013
README.textile added Example section Jan 1, 2013
_config.yml First release Jan 1, 2013
create_gallery.rb First release Jan 1, 2013

README.textile

What it is

CreateGallery is a ruby script and a set of layouts to generate a photo gallery in Jekyll.

Prerequisites

CreateGallery uses the following libraries:

To install EXIFR:

  gem install exifr

Installing CreateGallery

The only required file is create_gallery.rb.

If you want to take stock of the existing gallery layouts, you have two options:

  • Download this repository and copy the files in the _layouts directory in your Jekyll website
  • Use this repository as a Jekyll skeleton website.

If you are going to create your own gallery layouts, you can simply download the create_gallery.rb script.

How it works

Different from other Jekyll gallery generators, create_gallery.rb is a pre-processor.

That is, the script takes as input a list of directories containing pictures (either jpg or png) and it populates them with a set of thumbnails and a set of Jekyll files to nicely display the pictures as a gallery (where “nicely” depends upon how good you are with CSS and HTML gallery generation).

More specifically, given a directory gallery_1 containig the the files img-1.jpg and img-2.jpg, create_gallery.rb generates the following files in the gallery_1 directory:

  • Thumbnails (210×150 by default):
    • img-1-thumb.jpg: thumbnail of img-1.jpg
    • img-2-thumb.jpg: thumbnail of img-2.jpg
  • A textile page showing all the thumbnails in the gallery:
    • index.textile
  • (Optionally) a textile page for each picture:
    • img-1.textile (which shows img-1.jpg)
    • img-2.textile (which shows img-2.jpg)

Warning: The script silently overwrites the above mentioned files in the directory in which it is invoked.

Typical Workflow

  1. Add a directory containing pictures to your Jekyll website
  2. Run the create_gallery.rb script passing as input the directory name
  3. Run jekyll to generate your website

Link Generation

By default, create_gallery.rb uses relative URLs in the pages it generates. This should be ok in (nearly) all usage scenarios.

If you prefer to generate absolute pathnames, invoke the script using the --url option. In this case the directory portion of the URL will include the path of the file relative to the location in which the script has been invoked. When generating absolute URLs, therefore, it is a good idea to invoke the script from the root directory of your website.

Example

  $ cd <root of jekyll sources>
  $ ls -R
  gallery_1

  gallery_1:
  img-1.jpg img-2.jpg

  $ ./create_gallery.rb gallery_1 --url http://www.example.com/my_photo_website --pages
  [... which silently generates:
  - gallery_1/index.textile
  - gallery_1/1.textile
  - gallery_1/1-thumb.textile]

  $ jekyll --url http://www.example.com/my_photo_website

The website will have the following URLs:

  1. http://www.example.com/my_photo_website/gallery_1/index.html
  2. http://www.example.com/my_photo_website/gallery_1/img-1.html
  3. http://www.example.com/my_photo_website/gallery_1/img-2x.html

Customizing the Output

Nearly every aspect of the gallery can be configured using the layout files available in the _layouts directory. Have a look at the _layouts directory for more information.

Things to experiment:

  1. Customize the information which is displayed
  2. Embed the galleries in your website using your website look and feel
  3. Generate fancier galleries using Javascript: the html code generated by create_gallery.rb is compatible with Gallerific
  4. Generate your fancy layout

If you customize or create a new layout, please consider sending it to me, so that I can include it in the distribution. (Another possibility is forking the repository, add the new layout in the _layouts directory, and send a pull request.)

Command Options

Usage: 

  create_gallery [--pages] [--url URL] [--geometry <geometry>] <directory> ...

Input:  <directory> ... one or more directory with JPG or PNG pictures
Output: a set of Jekyll file to present the pictures as a gallery

Optional arguments:

  --geometry NNNxMMM generate thumbnails of given geometry (for the gallery
                     file)
  --pages            generate one individual page per picture (rather than
                     having the gallery point directly to the pictures)
  --url URL          make all links absolute

Some examples of thumb geometries: 330x220, 210x150 (app default), 90x90

License

Distributed under the terms of the MIT License

Example

  $ create_gallery.rb gallery_1
  $ jekyll

Limitations

… or opportunities for developers:

  • More interaction: ask before overwriting files
  • Generate scaled version of the images for the individual pages (at the moment pictures in individual pages are scaled using a width property of a css)
  • Support paging for larger galleries
  • Support gallery metadata (e.g. gallery caption, etc) (notice that this can be done now by manually editing the generated files)
  • Full support/improved support for Exif data
  • Integration with map services for pictures with GPS coordinates
  • Generation of an index pages including all galleries (with possible support for thumbnails)
  • Support for themes (when more than a layout is available)