def dump_to_file(self, tiled_map, file_path): """ 将tiled_map保存在给定的文件中 """ tiled_map_stream = StringIO() self.dump_to_stream(tiled_map, tiled_map_stream) tiled_map_stream.seek(0) compressed_bin = zlib.compress(tiled_map_stream.read()) with open(file_path, 'wb') as f: f.write(compressed_bin)
def get_png(self, fobj): output = StringIO() if isinstance(fobj, basestring): path = fobj if not path.startswith('/'): path = os.path.join(settings.MEDIA_ROOT, path) fobj = open(fobj) img = Image.open(fobj) img.save(output, format="PNG") output.seek(0) return output