Beispiel #1
0
def _resize_src(image, resize=False, **kwargs):
    # Load image
    if resize is None:
        image_src = appf.embed_image_html(image, target_width=None, target_height=None)
    elif resize:
        image = appf.resize_via_web_parameters(image)
        image_src = appf.embed_image_html(image, target_width=None, target_height=None)
    else:
        image_src = appf.embed_image_html(image)

    return image_src
Beispiel #2
0
def experiments_image_src(tag=None, **kwargs):
    tag = tag.strip().split('-')
    db = tag[0]
    gid = int(tag[1])

    ibs = experiment_init_db(db)
    config = {
        'thumbsize': 800,
    }
    gpath = ibs.get_image_thumbpath(gid, ensure_paths=True, **config)

    # Load image
    image = vt.imread(gpath, orient='auto')
    image = appf.resize_via_web_parameters(image)
    return appf.embed_image_html(image, target_width=None)
Beispiel #3
0
def image_src_api(rowid=None, thumbnail=False, fresh=False, **kwargs):
    r"""
    Returns the image file of image <gid>

    Example:
        >>> # xdoctest: +REQUIRES(--web)
        >>> from ibeis.web.app import *  # NOQA
        >>> import ibeis
        >>> web_ibs = ibeis.opendb_bg_web('testdb1', start_job_queue=False)
        >>> web_ibs.send_ibeis_request('/api/image/src/', type_='get', gid=1)
        >>> print(resp)
        >>> web_ibs.terminate2()

    RESTful:
        Method: GET
        URL:    /api/image/src/<rowid>/
    """
    from PIL import Image  # NOQA
    thumbnail = thumbnail or 'thumbnail' in request.args or 'thumbnail' in request.form
    ibs = current_app.ibs
    if thumbnail:
        gpath = ibs.get_image_thumbpath(rowid, ensure_paths=True)
        fresh = fresh or 'fresh' in request.args or 'fresh' in request.form
        if fresh:
            #import os
            #os.remove(gpath)
            ut.delete(gpath)
            gpath = ibs.get_image_thumbpath(rowid, ensure_paths=True)
    else:
        gpath = ibs.get_image_paths(rowid)

    # Load image
    assert gpath is not None, 'image path should not be None'
    image = vt.imread(gpath, orient='auto')
    image = appf.resize_via_web_parameters(image)
    image = image[:, :, ::-1]

    # Encode image
    image_pil = Image.fromarray(image)
    if six.PY2:
        img_io = StringIO()
    else:
        img_io = BytesIO()
    image_pil.save(img_io, 'JPEG', quality=100)
    img_io.seek(0)
    return send_file(img_io, mimetype='image/jpeg')
Beispiel #4
0
def image_src(gid=None, thumbnail=False, fresh=False, **kwargs):
    thumbnail = thumbnail or 'thumbnail' in request.args or 'thumbnail' in request.form
    ibs = current_app.ibs
    gid = int(gid)
    if thumbnail:
        gpath = ibs.get_image_thumbpath(gid, ensure_paths=True)
        fresh = fresh or 'fresh' in request.args or 'fresh' in request.form
        if fresh:
            import os
            os.remove(gpath)
            gpath = ibs.get_image_thumbpath(gid, ensure_paths=True)
    else:
        gpath = ibs.get_image_paths(gid)

    # Load image
    image = vt.imread(gpath, orient='auto')
    image = appf.resize_via_web_parameters(image)
    return appf.embed_image_html(image, target_width=None)
Beispiel #5
0
def image_src(gid=None, thumbnail=False, fresh=False, **kwargs):
    thumbnail = thumbnail or 'thumbnail' in request.args or 'thumbnail' in request.form
    ibs = current_app.ibs
    gid = int(gid)
    if thumbnail:
        gpath = ibs.get_image_thumbpath(gid, ensure_paths=True)
        fresh = fresh or 'fresh' in request.args or 'fresh' in request.form
        if fresh:
            import os
            os.remove(gpath)
            gpath = ibs.get_image_thumbpath(gid, ensure_paths=True)
    else:
        gpath = ibs.get_image_paths(gid)

    # Load image
    image = vt.imread(gpath, orient='auto')
    image = appf.resize_via_web_parameters(image)
    return appf.embed_image_html(image, target_width=None)
Beispiel #6
0
def image_src_api(gid=None, thumbnail=False, fresh=False, **kwargs):
    r"""
    Returns the image file of image <gid>

    Example:
        >>> # WEB_DOCTEST
        >>> from ibeis.web.app import *  # NOQA
        >>> import ibeis
        >>> web_ibs = ibeis.opendb_bg_web('testdb1', start_job_queue=False)
        >>> web_ibs.send_ibeis_request('/api/image/src/', type_='get', gid=1)
        >>> print(resp)
        >>> web_ibs.terminate2()

    RESTful:
        Method: GET
        URL:    /api/image/src/<gid>/
    """
    from PIL import Image  # NOQA
    thumbnail = thumbnail or 'thumbnail' in request.args or 'thumbnail' in request.form
    ibs = current_app.ibs
    if thumbnail:
        gpath = ibs.get_image_thumbpath(gid, ensure_paths=True)
        fresh = fresh or 'fresh' in request.args or 'fresh' in request.form
        if fresh:
            #import os
            #os.remove(gpath)
            ut.delete(gpath)
            gpath = ibs.get_image_thumbpath(gid, ensure_paths=True)
    else:
        gpath = ibs.get_image_paths(gid)

    # Load image
    assert gpath is not None, 'image path should not be None'
    image = vt.imread(gpath, orient='auto')
    image = appf.resize_via_web_parameters(image)
    image = image[:, :, ::-1]

    # Encode image
    image_pil = Image.fromarray(image)
    img_io = StringIO.StringIO()
    image_pil.save(img_io, 'JPEG', quality=100)
    img_io.seek(0)
    return send_file(img_io, mimetype='image/jpeg')
Beispiel #7
0
def background_src_api(rowid=None, fresh=False, **kwargs):
    r"""
    Returns the image file of annot <aid>

    Example:
        >>> # WEB_DOCTEST
        >>> from ibeis.web.app import *  # NOQA
        >>> import ibeis
        >>> web_ibs = ibeis.opendb_bg_web('testdb1', start_job_queue=False)
        >>> web_ibs.send_ibeis_request('/api/annot/src/', type_='get', aid=1)
        >>> print(resp)
        >>> web_ibs.terminate2()

    RESTful:
        Method: GET
        URL:    /api/annot/src/<rowid>/
    """
    from PIL import Image  # NOQA
    ibs = current_app.ibs
    gpath = ibs.get_annot_probchip_fpath(rowid)

    # Load image
    assert gpath is not None, 'image path should not be None'
    image = vt.imread(gpath, orient='auto')
    image = appf.resize_via_web_parameters(image)
    image = image[:, :, ::-1]

    # Encode image
    image_pil = Image.fromarray(image)
    if six.PY2:
        img_io = StringIO()
    else:
        img_io = BytesIO()
    image_pil.save(img_io, 'JPEG', quality=100)
    img_io.seek(0)
    return send_file(img_io, mimetype='image/jpeg')