def __init__(self, infile, media_id=None, filext='jpg', tilesize=256): """Create a new Tiler for tiling the media given by `media_id` with the image given by `infile`. If `media_id` is omitted, it will be set to `infile`. Tiles will be saved in the format indicated by `filext` and with the dimensions given by `tilesize`. """ Thread.__init__(self) self._infile = infile self.__filext = filext self.__tilesize = tilesize if media_id: self.__media_id = media_id else: self.__media_id = infile self.__outpath = TileStore.get_media_path(self.__media_id) self.__progress = 0.0 self.__logger = logging.getLogger(str(self)) self.error = None
def run(self): """Tile the image. If any errors are encountered then `self.error` will be set to a string describing the error. run() -> None """ self.__logger.debug("beginning tiling process") self.__maxtilelevel = self.__calculate_maxtilelevel() self.__numtiles = self.__calculate_numtiles() ## number of tiles that fit on the original image self.__numtiles_across_total = \ (self._width+self.__tilesize-1)//self.__tilesize self.__numtiles_down_total = \ (self._height+self.__tilesize-1)//self.__tilesize ## width and height of the right-most and bottom-most tiles ## respectively self.__right_tiles_width = (self._width - 1) % self.__tilesize + 1 self.__bottom_tiles_height = (self._height - 1) % self.__tilesize + 1 try: with TileStore.disk_lock: ## recursively tile the image self.__tiles() except Exception, e: self.error = str(e) outpath = TileStore.get_media_path(self.__media_id) shutil.rmtree(outpath, ignore_errors=True)