fixed image writing