fix some bug on saving image