A few small patches to image handling

1. tweak double-encode logic for image data

   Instead of only b64-encoding for valid image data, b64-encode unless it is specifically detected as b64-encoded valid image data. This prevents garbage data from skipping the b64 step, and causing unicode errors.
2. check image header to identify image type
3. allow Image("filename")

   We already support passing a URL this way,
   it's silly to not support passing a filename,
   as user reports have shown many times.

Closes #3081