Adding function to write image from array