Autodetect jpg images.

Fixes ticket #2541.