put long code into validate_image_* functions