Gallery »Sample gallery«

Created by »makethumbsf6« — 2017-04-28 20:50 — PhotoSwipe included — Like it? Read about donating.

This is just a very simple test page where all images stretch out to maximum width. For your convenience, I’ve included the PhotoSwipe lightbox: Just click on a thumbnail and the image will open in the lightbox!

Responsive is great!

All images are »responsive«. That means you can resize your browser window as you like, or rotate your tablet or smartphone, and you’ll always get the best image possible. Beautiful image quality on the smallest handheld device as well as on the largest 75-inch 4K TV set!

Yes, but who will create all those different image sizes for me?

This script, makethumbsf6, will do all it for you!

It can automatically create thumbnails as well as small and web-optimized versions of your beautiful originals, without ever modifying the original. Makethumbsf6 will also create perfect, validating HTML5 responsive markup for you, including optimal code for a lightbox and SEO-optimized schema.org markup. All you have to do is copy and paste the generated image code!

Get image data and perfect markup … automagically.

All modern digital images can (and do) hold image information like where and when a shot was taken, camera settings, a description of the image content, and maybe even the photographer’s name. Finally, all image information travels together with—and actually inside—your image: It’s all here for you—no manual markup needed!

You only add the additional info you want—directly into the image. These might be: A title, an image description, the photographer’s name, the company or agency he works for, and maybe a copyright notice. Many professional cameras have a setting where you can store your name and copyright notice so these will be attached automatically to each image whenever taking a shot. Almost all images from agencies or news services use this image information already.

So how can you take advantage of all this?

It’s easy. Read more below the images!


See what you got!

Just great! How does it work?

Pretty easy. You need a system with a bash shell and exiftool, ImageMagick and Python installed.

Then follow these five simple steps:

  1. Get hold of my script, save it to a place where the system can find it (I recommend ~/bin on Linux systems), and give it execute rights (chmod +x makethumbsf6). This step is only needed once.
  2. Copy all images you want for any one gallery page into a folder. (If you are working with Zurb’s Foundation 6 framework, this is most probably something like projectfolder/src/assets/img/gallery/album-01.)
  3. Add all extra image information you want or need directly into the images, using a tool like exiftool. If you have nothing else (like maybe Adobe PhotoShop or Lightroom), you can even use Mac OSX’s Finder, or the Windows Image Properties dialog. (If you are unsure, you can skip this step and do it later. Then simply run my script again.)
  4. Open a shell (or command prompt), change to the folder containing the images, and run makethumbsf6. This will take a moment while it generates thumbnails and optimized smaller images in subfolders called t, ts, s, m, l and xl. These will contain thumbnails, squared/cropped thumbnails, and small, medium, large and extra-large versions of your images, respectively.
  5. The script also generates a HTML test page like this one, called gallery-path-name.html. (If it detects you are working in a Foundation 6 directory structure, it will instead generate a partial called gallery-path-name.html. This can later be directly included in your page using Panini’s {{> gallery-path-name gid=1}}.)

Et voilà! My script has done its magic, and you can use the results however you wish. Copy optimized, responsive and SEO-friendly code from this sample page, or watch the live changes in your Foundation 6 workflow (if foundation watch is being run).

Now how does it really work?

I mainly extract a lot of information from the images and build a HTML5/CSS3/Foundation 6 compatible source from it.

Since doing all that manually can be a lot of work (and quite error-prone), my script takes the hassle out of it and does most of the work for you.

From your original images (which are never changed), I also build thumbnails and smaller, web-optimized versions for responsive delivery. That means, on a mobile device you’ll get smaller images than on a large desktop. It makes delivering over low-bandwith connections blazingly fast while you don’t have to do all the work manually!

The mechanisms I use (img srcsets and sizes) also work great with Retina displays (2x), because eventually the browser intelligently decides which image to load. Even rotating a mobile device by 90° is no problem anymore—you’ll always get the smallest and best quality image delivered.

No Javascript involved—if you don’t want it. Nevertheless, the image markup generated works just great with many available JS lightbox scripts, like PhotoSwipe (which I recommend because it has great mobile features and is framework-independent).

Almost everything is configurable

Not enough yet? You can change almost anything, with a few keystrokes:

Documentation, please …?

Still not enough? Study the code of this single bash script. It is very well documented and can be opened with any text editor than can read/write UTF-8 encoded text files.

Change to your heart’s content. Fork makethumbsf6 on GitHub and make a pull request if you feel that you added something of general interest, or improved it!

Some more hints:

Working with Zurb’s Foundation 6 framework

  1. Serve the PhotoSwipe files locally. Download them and put the contents of the dist folder into a newly-created src/assets/photoswipe/ folder.
  2. Study this HTML file (search for <!-- PhotoSwipe custom code:) and copy-paste the code between the next <script> and </script> tags into a separate file src/assets/photoswipe/photoswipe-custom.js.
  3. Search for <!-- Start PhotoSwipe code --> and copy-paste from this line and up to—but not including—the line <!-- PhotoSwipe Javascript (delivered from CDN for standalone) --> into a new file src/partials/gallery.html. At the end of that new file, add the following lines:
    <!-- PhotoSwipe Javascript -->
    <script src="{{root}}assets/photoswipe/photoswipe.min.js"></script>
    <script src="{{root}}assets/photoswipe/photoswipe-ui-default.min.js"></script>
    <!-- PhotoSwipe custom code: Get gallery from DOM -->
    <script src="{{root}}assets/photoswipe/photoswipe-custom.js"></script>
    <!-- End PhotoSwipe code -->
  4. Create a gallery page, let’s call it src/pages/gallerypage.html.
  5. Modify your src/layouts/default.html’s <head> area to include the Photoswipe CSS files:
    {{#ifpage 'gallerypage'}}
    <!-- gallery page(s) -->
    <link rel="stylesheet" href="{{root}}assets/photoswipe/photoswipe.min.css">
    <link rel="stylesheet" href="{{root}}assets/photoswipe/default-skin/default-skin.min.css">
    {{/ifpage}}
  6. — Take a break. — Steps 1 thru 5 only need to be done once.
  7. Make a folder for your first album: src/assets/img/gallery/album-01 and put some original photos there.
  8. In a terminal (command prompt), cd to your album folder, i.e. cd ~/projects/test/src/assets/img/gallery/album-01. Or use your file manager, right-click on the subfolder album-01 and select "Open terminal here" (the wording can differ a little between desktop environments).
  9. In this folder, on the command line, run makethumbsf6. It will automatically detect that you run it within a Foundation 6 folder structure and output some information while it proceeds, creating the miscellaneous subfolders and images for different resolutions.
  10. When makethumbsf6 is finished, it will have created a new gallery partial for you, called src/partials/gallery-gallery-album-01.html in this example.
  11. In the new gallery page created above (src/pages/gallerypage.html), somewhere near the end, now add some Panini code to include your new gallery album:
    {{!-- include gallery/galleries created by makethumbsf6 --}}
    {{!-- specify "gid=#" if using more than one gallery on one single page --}}
    {{> gallery-gallery-album-01 gid=1}}

    {{!-- include PhotoSwipe code --}}
    {{> gallery}}

    <!-- end content -->
  12. Done! You now have a perfectly running gallery, with a low-footprint, fast and feature-rich lightbox!
  13. If you have foundation watch running, you can even watch the live page updating the gallery whenever you re-run makethumbsf6 in your album folder! Remember that makethumbsf6 will neither erase or recreate images already built (this helps speeding things up), so if you change images and/or their data, you might want to manually remove the subfolders under album-01 in order to force makethumbsf6 building a fresh set.
  14. Now you can play around and optimize your new gallery to your heart’s content. You may want to modify some settings within makethumbsf6 itself, or even modify src/partials/gallery.html or src/assets/photoswipe/photoswipe-custom.js. The possibilities are endless—enjoy!
  15. N.B.: Use exiftool to enter all relevant data into your images and have makethumbsf6 create beautiful captions, with headlines and map links even, all automatic and SEO-optimized!

Some exiftool commands I recommend to get going

Set photographer/artist name for all *.jpg in a folder:
exiftool -by-line="Alfred E. Newman" *.jpg
Note: Some modern cameras can set the photographer’s name in the EXIF data. Should you need to overwrite that, use the following instead:
exiftool -exif:artist="Alfred E. Newman" *.jpg
Set credits (stock photo or other agency, company) for single image:
exiftool -credit="M. Hormann Webdesign" "999-Matthias C. Hormann - Der Problemlöser.jpg"
(Image filename in apostrophes since it contains blanks.)
Set headline for a single image:
exiftool -headline="Eiseskälte in Bad Grönenbach" "040-winter-in-bad-grönenbach.jpg"
(Character encoding must be UTF-8, so almost all foreign characters can be used.)
Set caption text (description) for an image:
exiftool -caption-abstract="Long description (up to 2000 chars) …" 052-the-coding-phase.jpeg
Set copyright notice for all *.jpg images in a folder:
exiftool -copyrightnotice="Copyright © 2017 Matthias C. Hormann, all rights reserved." *.jpg
Note: Some modern cameras can set a copyright notice in the EXIF data. Should you need to overwrite that, use the following instead:
exiftool -exif:copyright="Copyright © 2017 Matthias C. Hormann, all rights reserved." *.jpg
Erase location data (GPS) so it won’t be published (and no automatic map links generated):
exiftool -gps:all= "040-winter-in-bad-grönenbach.jpg"
Caution: You cannot get this information back (except from a backup)! A better way might be to just set USE_MAPS=false in the script.
Set some keywords for an image (not used in this script but might be handy elsewhere):
exiftool -keywords="webdesign,problem solver,programming,linux" "999-Matthias C. Hormann - Der Problemlöser.jpg"

Wow! What does it cost?

Short answer? Nothing. It’s Free and Open-Source Software (FOSS) and MIT-licensed, so you can almost do what you want with it. Even use it for commercial purposes. I only claim that you shouldn’t steal it. Just leave the examples as they are, don’t change the copyrights and leave my name in. Oh well, and quote me, maybe give a backlink.

This took several weeks to make and debug, and is still being actively debugged (and used everyday).

Don’t feel obliged. You don’t have to. But if I could help you, why not help back? You’ll get this warm, fuzzy feeling inside and you’ll know that you’ve moved something … :-)

Let us know what you think. How you use it.

Thank you! I really appreciate it, and it’ll certainly help keeping more nice things coming!

Script »makethumbsf6« Copyright © 2017 Matthias C. Hormann. All rights reserved. Urheberrechtlich geschützt, alle Rechte vorbehalten.

All this wouldn’t have been possible without …