def __init__(self, dp, **kw): DefaultRenderer.__init__(self, dp, **kw) Purr.progressMessage("rendering %s" % dp.filename, sub=True) img = PIL.Image.open(dp.fullpath) # If image format is not compatible with browsers, save it in PNG format. # self.fullimage will refer to the browser-compatible image, to which the thumbnail will link if img.format not in ["GIF", "JPEG", "PNG"]: self.fullimage, path, uptodate = self.subproduct("-full.png") if not uptodate: try: img.save(path, "PNG") except: print("Error saving %s in PNG format" % path) traceback.print_exc() self.fullimage = dp.filename else: self.fullimage = dp.filename # now, do we need to generate a thumbnail? tsize = self.getOption("image-thumbnail-width"), self.getOption("image-thumbnail-height") width, height = img.size factors = width / float(tsize[0]), height / float(tsize[1]) if max(factors) <= 1: self.thumbnail = self.fullimage else: # regenerate thumbnail if needed self.thumbnail, path, uptodate = self.subproduct("-thumb.png") try: # regenerate only if doesn't exist if not uptodate: # use max resize factor factor = max(factors) img = img.resize((int(width / factor), int(height / factor)), PIL.Image.ANTIALIAS) img.save(path, "PNG") except: print("Error saving thumbnail %s in PNG format" % path) traceback.print_exc() self.thumbnail = None
def __init__(self, dp, refresh=0): DefaultRenderer.__init__(self, dp, refresh=refresh) self.rendercache = {} self._regenerated = False