fixed a bug for when generating code for image