Fix preview generation on malformed images