Fgallery: Free software for fast, always centered photo galleries

Marco Fioretti takes a look at fgallery, a free software tool that allows you to build static photo albums.

Online photo galleries are a fun and very practical way to share photographs. Hosting galleries on a web space that you own gives you much more privacy and control over the reuse of those images than places like Facebook or Flickr. If you like that idea, you'll probably also like the way to implement it that I propose this week -- that is, static galleries, or simple folders that contain the actual pictures and almost nothing else, without any sophisticated gallery management software. Albums like this can be hosted on free, throwaway web accounts, and they work fast, despite not being on powerful (that is, expensive) web servers.

There are many free software tools to build static photo albums. One example is fgallery, which creates very simple but good looking albums and can use facedetect, the face detection utility that I previously wrote about in TechRepublic's Linux and Open Source blog.

Fgallery depends on the ImageMagick graphic tools that are almost surely already present in your GNU/Linux distribution, plus two other utilities: exiftran, which (on my Fedora box) comes in a package called fbida, and the JSON-PP Perl module. The JSON library should be available as a binary package for the most common distributions. On Fedora, for example, I immediately found it in the default repositories and installed it with these two commands:

[root@polaris ~]# yum search perl | grep -i json | grep -i pp
perl-JSON-PP.noarch : JSON::XS compatible pure-Perl module
[root@polaris ~]# yum install perl-JSON-PP

In addition to these basic dependencies, fgallery may optionally use two programs called jpegoptim and pngcrush to reduce the size of the uploaded pictures with the smallest possible impact on their quality.

Fgallery comes as one package, but in reality, it consists of two independent objects. One is a Perl script called fgallery -- this is the software that prepares all the pictures and thumbnails, plus a metadata file called data.json. The other component is the content of the "view" directory that you find inside the fgallery ZIP archive. This folder contains the HTML files and JavaScript code that display the gallery in your browser and let you navigate it.

In order to show you how these two objects work together, I decided to create a gallery on my computer that would show up in my browser as a real Internet web site. First, I put a selection of photographs from some conferences into a folder that I simply called "photo."

Next, I copied the whole "view" directory to a location that my local web server would show at the URL http://localhost/fgallery/freesoftware_events_2013:

#> cp -r view /var/www/html/fgallery/freesoftware_events_2013

Finally, I told fgallery to fill that folder with copies of the pictures inside the "photo" directory:

#> fgallery photo /var/www/html/fgallery/freesoftware_events_2013
0% odwm_marseille_2.jpg ...
4% P1170745.jpg ...
9% P1170749.jpg ...
83% P1200679.jpg ...
87% P1200687.jpg ...
91% sfk13_cake_2.jpg ...
96% sfk13_friends.jpg ...
100% completed

Figure A shows the gallery when the script was finished. The thumbnails automatically place themselves at the bottom or on the right side, depending on the size of the browser window. By default, you get a button that you can use to download the whole album as one zipped file (to disable this function, pass the -d option to fgallery).

Figure A

Figure A
Creating a gallery with fgallery.

The sizes of the thumbnails and the larger images are controlled via the --min-thumb, --max-thumb, and --max-full switches. The script also rotates the images according to their EXIF tags. Fgallery does other nice things as well, like automatic detection of panoramic images in order to include the original versions in the album. It also allows you to take advantage of face detection, as I mentioned above.

I created another gallery with the same content, but I told fgallery to use facedetect to create, when possible, thumbnails centered around faces (Figure B). The way to do this is to pass the -f option to the script:

#> fgallery -f photo /var/www/html/fgallery/facedetect/

Figure B

Figure B

Fgallery using facedetect.

The left column contains the thumbnails generated by the default options, and the right column contains the thumbnails generated from face detection. Indeed, the two top thumbnails on the right are more centered on faces than the others. In my experience, the effectiveness of face detection depends on the minimum and maximum sizes you set for the thumbnails (those in Figure B were generated with --min-thumb 80x80 --max-thumb 100x100). However, in general, I've found this feature to work as expected -- that is, to be actually useful and make more interesting thumbnails. 

Do you use fgallery or another free software tool for creating photo galleries? Share your experience in the discussion thread below.