Fix double encoding of images

This fixes the issue described in issue #12