writeImage function commented in