[TS().write()] fix many bugs in img writing