def scaled_image(height, filename): filename = clean_url_path(filename) if filename not in all_images(): abort(404, "image not found") if height not in HEIGHTS: abort(404, "No scaled image of that height available.") outfile = os.path.splitext(filename)[0] + ".thumbnail.%d.jpg" % height if os.path.isfile(os.path.join(THUMBS_DIR, outfile)): return static_file(outfile, root=THUMBS_DIR) try: with Image.open(os.path.join(IMAGE_FOLDER, filename)) as im: size = (height*2, height) exif = im._getexif() if exif != None: for tag, value in exif.items(): decoded = ExifTags.TAGS.get(tag, tag) if decoded == 'Orientation': if value == 3: im = im.rotate(180, expand=True) if value == 6: im = im.rotate(270, expand=True) if value == 8: im = im.rotate(90, expand=True) break im.thumbnail(size, Image.ANTIALIAS) mkdir_p(os.path.split(os.path.join(THUMBS_DIR, outfile))[0]) im.save(os.path.join(THUMBS_DIR, outfile), "JPEG", quality=JPEG_QUALITY) except (IOError, NameError): abort(500, "cannot create thumbnail for '%s'" % filename) return static_file(outfile, root=THUMBS_DIR)
def full_size_image(filename): filename = clean_url_path(filename) dl = bool(request.query.get('dl', False)) if dl: return static_file(filename, root=IMAGE_FOLDER, download=os.path.split(filename)[1]) else: return static_file(filename, root=IMAGE_FOLDER)
def static(path): return static_file(path, root=STATIC_PATH)