Bash script to automatically generate thumbnails and gallery HTML on file system changes.
A little script to help automate the process of creating a flat single page photo gallery. This was originally designed for Ghost Blog, but could easily be modified for a standalone gallery page or integration into another content management system. The generated HTML is designed for use with fancybox3 as a lightbox gallery. This implementation of the script assumes incron, the inotify cron system initaites the script upon file system changes in a monitored directory; however, the script can be called by any means (e.g. cron, command line) as long as the expected arguments are passed.
When images are added to a monitored directory, incron will call the script to generate a thumbnail and append the relavent HTML to the end of the gallery file.
When images are deleted from a monitored directory, incron will call the script to delete the associated thumbnail and HTML.
- Linux Distro for basic commands (e.g. sed, rm, echo)
- Imagemagick for thumbnail generation.
The script accepts three arguments
- Path to base directory
- File initiating event, e.g. image that needs to be added or removed from the gallery)
- Event. May be either IN_CREATE, adding an image to the gallery, or IN_DELETE, removing an image from the gallery.
Assumed File Structure
Please modify your file structure
- / : monitored directory
- /core : generated HTML
- /t : Thumbnails
- Script may be located anywhere as long as the path argument that is passed when script is invoked refers to / (directory base)
Example Gallery in a Ghost Blog
Instructions for Integrating Into Ghost
Documentation for one method of integrating this script with Ghost and setting up an automated photo gallery may be found at: https://stevengerner.com/automatic-photo-gallery-with-ghost-blog/