Fix images sometimes get saved without an extension. Use the image type to detect the extension in this case.