Added argument for format during image writing