Returns a well-formed image
    :param name: file name of the image
    :param kwargs: additional attributes and values
    :return: a well-formed html img
770369
def get_image(name, **kwargs):
    
    if not name:
        return ""
    portal_url = api.get_url(api.get_portal())
    attr = render_html_attributes(**kwargs)
    html = '<img src="{}/++resource++bika.lims.images/{}" {}/>'
    return html.format(portal_url, name, attr)
572114
def make_img_widget(cls, img, layout=Layout(), format='jpg'):
        ""
        return widgets.Image(value=img, format=format, layout=layout)
857261
def image_name(image, key='name', clear=True):
    
    if hasattr(image, 'translation') and image.translation:
        return getattr(image.translation, key)

    if hasattr(image, key) and getattr(image, key):
        return getattr(image, key)

    try:
        name = IMAGE_NAME.match(image.original_filename).group()
    except IndexError:
        return ''
    else:
        name = name[:-1]
        if clear:
            return name.replace("_", " ").replace("-", " ")
        return name
919357
def image(self):
        
        if self._image is None:
            self._image = Image(self.fname)
        return self._image
1191177
def img(self, id):
        """"""
        return self._serve_file(os.path.join(media_path, 'img', id))
328775
def image_by_name(img_name, images=None):
    
    i_reg, i_rep, i_tag = _decompose(img_name)

    # Correct for bash-style matching expressions.
    if not i_reg:
        i_reg = '*'
    if not i_tag:
        i_tag = '*'

    # If the images were not passed in, go get them.
    if images is None:
        c = docker.Client(**kwargs_from_env())
        images = c.images(all=False)

    valid_images = []
    for i in images:
        for t in i['RepoTags']:
            reg, rep, tag = _decompose(t)
            if matches(reg, i_reg) \
                    and matches(rep, i_rep) \
                    and matches(tag, i_tag):
                valid_images.append(i)
                break
            # Some repo after decompose end up with the img_name
            # at the end.  i.e. rhel7/rsyslog
            if rep.endswith(img_name):
                valid_images.append(i)
                break
    return valid_images
267329
def format_image(self, image, image_format, **kwargs):
        """"""

        image_format = image_format.lower()
        accept = self.request.META['HTTP_ACCEPT'].split(',')

        if FORCE_WEBP and 'image/webp' in accept:
            image_format = 'webp'
        elif image_format == 'png8':
            alpha = image.split()[-1]
            image = image.convert('RGB')
            image = image.convert('P', palette=Image.ADAPTIVE, colors=255)
            image.paste(255, Image.eval(alpha, lambda x: 255 if x <= 128 else 0))
            image_format = 'png'
            kwargs['transparency'] = 255
        elif image_format in ('png32', 'png24'):
            image_format = 'png'

        return super(GetImageView, self).format_image(image, image_format, **kwargs)
157216
def get_template_image(kwargs=None, call=None):
    '''
    
    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The get_template_image function must be called with -f or --function.'
        )

    if kwargs is None:
        kwargs = {}

    name = kwargs.get('name', None)
    if name is None:
        raise SaltCloudSystemExit(
            'The get_template_image function requires a \'name\'.'
        )

    try:
        ret = list_templates()[name]['template']['disk']['image']
    except KeyError:
        raise SaltCloudSystemExit(
            'The image for template \'{0}\' could not be found.'.format(name)
        )

    return ret
459660
def get_thumbnail(file_, name):
    
    options = settings.OPTIONS_DICT[name]
    opt = copy(options)
    geometry = opt.pop('geometry')

    return original_get_thumbnail(file_, geometry, **opt)
857938
def avail_images(kwargs=None, call=None):
    '''
    
    '''
    if call == 'action':
        raise SaltCloudSystemExit(
            'The avail_images function must be called with '
            '-f or --function, or with the --list-images option'
        )

    if not isinstance(kwargs, dict):
        kwargs = {}

    provider = get_configured_provider()
    location = provider.get('location', DEFAULT_LOCATION)

    if 'location' in kwargs:
        location = kwargs['location']

    params = {
        'Action': 'DescribeImages',
        'RegionId': location,
        'PageSize': '100',
    }
    items = query(params=params)

    ret = {}
    for image in items['Images']['Image']:
        ret[image['ImageId']] = {}
        for item in image:
            ret[image['ImageId']][item] = six.text_type(image[item])

    return ret
570645
def load_img(name):
    """"""

    fullname = name
    try:
        image = pygame.image.load(fullname)
        if image.get_alpha() is None:
            image = image.convert()
        else:
            image = image.convert_alpha()
    except pygame.error, message:
        print "Error: couldn't load image: ", fullname
        raise SystemExit, message
    return (image, image.get_rect())
1126094
def embed_image_html(image):
    
    if image is None:
        return None
    elif isinstance(image, PIL.Image.Image):
        pass
    elif isinstance(image, np.ndarray):
        image = PIL.Image.fromarray(image)
    else:
        raise ValueError('image must be a PIL.Image or a np.ndarray')

    # Read format from the image
    fmt = image.format
    if not fmt:
        # default to JPEG
        fmt = 'jpeg'
    else:
        fmt = fmt.lower()

    string_buf = StringIO()
    image.save(string_buf, format=fmt)
    data = string_buf.getvalue().encode('base64').replace('\n', '')
    return 'data:image/%s;base64,%s' % (fmt, data)
1316216
def build_image_from_inherited_image(self, image_name: str, image_tag: str,
                                         repo_path: Path,
                                         requirements_option: RequirementsOptions):
        

        base_name, base_tag = self.get_inherit_image()

        if requirements_option == RequirementsOptions.no_requirements:
            image = self.get_image(base_name, base_tag)
            image.tag(image_name, image_tag)  # so ``build_image`` doesn't have to be called next time

            return image

        dockerfile = self.get_install_requirements_dockerfile(base_name, base_tag, repo_path, requirements_option)

        self.get_or_build_image(image_name, image_tag, dockerfile, build_context=repo_path.parent, pull=False)

        return self.get_image(image_name, image_tag)
1276877
def load_image(fname):
    
    with open(fname, "rb") as f:
        i = Image.open(fname)
        #i.load()
        return i
635192
def _get_img_attrs(self, style, kwargs):
        

        # Get the 1x and 2x renditions
        img_1x, img_2x, size = self._get_renditions(kwargs)

        return {
            'src': img_1x,
            'width': size[0],
            'height': size[1],
            'srcset': "{} 1x, {} 2x".format(img_1x, img_2x) if img_1x != img_2x else None,
            'style': ';'.join(style) if style else None,
            'class': kwargs.get('class', kwargs.get('img_class')),
            'id': kwargs.get('img_id')
        }
574906
def url_to_image(url, flag=cv2.IMREAD_COLOR):
    
    resp = urlopen(url)
    image = np.asarray(bytearray(resp.read()), dtype="uint8")
    image = cv2.imdecode(image, flag)
    return image
859486
def _get_renditions(self, kwargs):
        
        img_1x, size = self.get_rendition(
            1, **utils.remap_args(kwargs, {"quality": "quality_ldpi"}))
        img_2x, _ = self.get_rendition(
            2, **utils.remap_args(kwargs, {"quality": "quality_hdpi"}))

        return (img_1x, img_2x, size)