Here is an example using the "HappyFiles gallery" instead of a category query. Just add images to a folder in HappyFiles (access in media) and use the category as the source. Note, the pictures are set to not crop. This results in the masonry layout. Easy peasy!