Deal with the first image in gallery button being locked.

Fixes #410, and adds a test case for the gallery.