def loadTile(self, z, tx, ty): filecache = "%s/%s/%d/%d/%d.%s" % (self.cache_path, self.source, z, tx, ty, self.extensions[self.filetype]) url = tilenames.getTileUrl(tx, ty, z, self.source, self.filetype.lower()) try: img = Image.open(filecache) # print "opened image:", filecache except IOError: ready = False while not ready: try: print "download", filecache, "to cache..." # print url tmp = urllib.urlretrieve(url) img = Image.open(tmp[0]) if self.source == "landsat": img = img.resize((256, 256), Image.ANTIALIAS) myutils.createPath(filecache) if self.filetype != "JPEG": img.save(filecache, self.filetype) else: img.save(filecache, self.filetype, quality=self.quality) ready = True except KeyboardInterrupt: exit(0) except: print "Unexpected error: %s" % sys.exc_info()[0] time.sleep(1) ready = False return img
def saveImage(self): scan_file = self.getFileName() myutils.createPath(scan_file) print "saving file:", scan_file if self.filetype == "JPEG": self.scan_img.save(scan_file,self.filetype,quality=self.quality) else: self.scan_img.save(scan_file,self.filetype) self.scan_img = Image.new("RGB",(self.width,self.height),(255,255,255))