def get_page_image_thumb(workflow, seq_num, img_type, plugname): """ Return thumbnail for page image from requested workflow. """ if img_type not in ('raw', 'processed'): raise ApiException("Image type must be one of 'raw' or 'processed', " "not '{0}'".format(img_type), 400) if img_type == 'processed' and plugname is None: raise ApiException("Need to supply additional path parameter for " "plugin to get processed file for.", 400) page = get_next(p for p in workflow.pages if p.sequence_num == seq_num) if not page: raise ApiException("Could not find page with sequence number {0}" .format(seq_num), 404) if img_type == 'raw': fpath = page.raw_image elif plugname is None: fpath = page.get_latest_processed(image_only=True) else: fpath = page.processed_images[plugname] if fpath.suffix.lower() not in ('.jpg', '.jpeg', '.tif', '.tiff', '.png'): raise ApiException("Can not serve thumbnails for files with type {0}" .format(fpath.suffix), 400) cache_key = "{0}.{1}.{2}".format(workflow.id, img_type, fpath.name) thumbnail = None if not request.args: thumbnail = cache.get(cache_key) if thumbnail is None: thumbnail = get_thumbnail(fpath) cache.set(cache_key, thumbnail) return Response(thumbnail, mimetype='image/jpeg')
def get_page_image_thumb(fpath, page, workflow, number, img_type, plugname): """ Get thumbnail for a page image. """ if fpath.suffix.lower() not in ('.jpg', '.jpeg', '.tif', '.tiff', '.png'): raise ApiException("Can not serve thumbnails for files with type {0}" .format(fpath.suffix), 400) cache_key = "{0}.{1}.{2}".format(workflow.id, img_type, fpath.name) thumbnail = None if not request.args: thumbnail = cache.get(cache_key) if thumbnail is None: thumbnail = get_thumbnail(fpath) cache.set(cache_key, thumbnail) return Response(thumbnail, mimetype='image/jpeg')
def get_workflow_image_thumb(workflow, img_num): """ Return thumbnail for image from requested workflow. """ try: img_path = workflow.images[img_num] except IndexError: abort(404) cache_key = "{0}.{1}".format(workflow, img_num) thumbnail = None if not request.args: thumbnail = cache.get(cache_key) if thumbnail is None: thumbnail = get_thumbnail(img_path) cache.set(cache_key, thumbnail) return Response(thumbnail, mimetype='image/jpeg')
def get_page_image_thumb(workflow, number, img_type, plugname): """ Return thumbnail for page image from requested workflow. """ page = find_page(workflow, number) check_page_params(page, img_type, plugname) if img_type == 'raw': fpath = page.raw_image elif plugname is None: fpath = page.get_latest_processed(image_only=True) else: fpath = page.processed_images[plugname] if fpath.suffix.lower() not in ('.jpg', '.jpeg', '.tif', '.tiff', '.png'): raise ApiException("Can not serve thumbnails for files with type {0}" .format(fpath.suffix), 500) cache_key = "{0}.{1}.{2}".format(workflow.id, img_type, fpath.name) thumbnail = None if not request.args: thumbnail = cache.get(cache_key) if thumbnail is None: thumbnail = get_thumbnail(fpath) cache.set(cache_key, thumbnail) return Response(thumbnail, mimetype='image/jpeg')