Add support for image metadata

This PR replaces #266 and should solve #222 and #190