def _try_generating_thumbnail_url(rel_path, alias=None): """ Falls back to original fail url if thumbnail generation fails, or if no alias is provided. """ if alias: try: thumb = get_game_thumbnailer(rel_path)[alias] # we enforce the GAME_FILES storage here! return thumb.url except Exception, e: logging.warning("Error generating game_file_img %s (alias=%s): %r", rel_path, alias, e) pass # fallback to plain file
def _try_generating_thumbnail_url(rel_path, alias=None): """ Falls back to original fail url if thumbnail generation fails, or if no alias is provided. """ if alias: try: thumb = get_game_thumbnailer(rel_path)[ alias] # we enforce the GAME_FILES storage here! return thumb.url except Exception as e: logging.warning("Error generating game_file_img %s (alias=%s): %r", rel_path, alias, e) pass # fallback to plain file return real_game_file_url(rel_path) # original image
def generate_image_viewer(imageurl, width=300, height=300, preset=None, align="", **kwargs): """ Align, if not empty, can be center/left/right. """ md5 = hashlib.md5() md5.update(imageurl.encode('ascii', 'ignore')) myhash = md5.hexdigest()[0:8] thumb = None rel_path = checked_game_file_path(imageurl) if not rel_path: thumburl = imageurl # this might just not be an internal, secure, image else: try: # this url is actually a local game file thumbnailer = get_game_thumbnailer(rel_path) thumb = None if preset: try: thumb = thumbnailer[preset] except Exception, e: # eg. if preset name is unexisting logging.critical("generate_image_viewer preset selection failed for %s/%s", imageurl, preset, exc_info=True) pass if not thumb: #we fallback to default options options = { 'autocrop': False, # remove useless whitespace 'crop': False, # no cropping at all,thumb must fit in both W and H 'size': (width, height), # one of these can be 0 } thumb = thumbnailer.get_thumbnail(options) thumburl = thumb.url except Exception, e: logging.critical("generate_image_viewer thumbnail generation failed %s - %s", imageurl, preset, exc_info=True) thumburl = imageurl # we give up thumbnailing...
def generate_image_viewer(imageurl, width=500, height=400, preset=None, align="", **kwargs): """ Generates an image thumbnail linking to the original image. Align, if not empty, can be center/left/right. """ md5 = hashlib.md5() md5.update(imageurl.encode('ascii', 'ignore')) myhash = md5.hexdigest()[0:8] thumb = None rel_path = checked_game_file_path(imageurl) if not rel_path: thumburl = imageurl # this might just not be an internal, secure, image else: try: # this url is actually a local game file thumbnailer = get_game_thumbnailer(rel_path) if preset: try: thumb = thumbnailer[preset] except Exception as e: # eg. if preset name is unexisting logging.critical( "generate_image_viewer preset selection failed for %s/%s", imageurl, preset, exc_info=True) pass if not thumb: #we fallback to default options options = { 'autocrop': False, # remove useless whitespace 'crop': False, # no cropping at all,thumb must fit in both W and H 'size': (width, height), # one of these can be 0 } thumb = thumbnailer.get_thumbnail(options) thumburl = thumb.url except Exception as e: logging.critical( "generate_image_viewer thumbnail generation failed %s - %s", imageurl, preset, exc_info=True) thumburl = imageurl # we give up thumbnailing... options = \ { "title": "", # no title for now "id": myhash, "imageurl": escape(imageurl), "thumburl": escape(thumburl), "width": escape(thumb.width if thumb else width), "height": escape(thumb.height if thumb else height), "classes": "align-%s" % align if align else "", } template = ( """<a href="%(imageurl)s"><img class="imageviewer %(classes)s" src="%(thumburl)s" title="%(title)s" id="%(id)s" """ + """style="max-width: %(width)spx; max-height:%(height)spx"/></a>""") return template % options