I dont see why not, Im not familar with the gallery mod however. Is there a link available for it. I could install it on my test forum and then work on integrating this code.
that code should work on all images withen your site if placed in the proper template.. Very much like this similier code im using for pinterest.
--------------
edit: but i like your find way better.. might have to take it for a test spin..