writing images to files as PNG format