Security fixes for downloaded images (thanks @leblanc-simon)

If an image has php code in it, it can be executed and do anything.
We check that it's really an image and regenerate it.