fixed bug in gen_image