Returns either the :tl:`WebDocument` thumbnail for
        normal results or the :tl:`Photo` for media results.
423786
def photo(self):
        
        if isinstance(self.result, types.BotInlineResult):
            return self.result.thumb
        elif isinstance(self.result, types.BotInlineMediaResult):
            return self.result.photo
120112
def get_thumbnail_image(self, page=1):
        
        url = self.get_thumbnail_image_url(page=page)
        return self._get_url(url)
695763
def thumbnail(self):
        
        if 'THUMBNAIL_RESOURCE' in self.image_resources:
            return pil_io.convert_thumbnail_to_pil(
                self.image_resources.get_data('THUMBNAIL_RESOURCE')
            )
        elif 'THUMBNAIL_RESOURCE_PS4' in self.image_resources:
            return pil_io.convert_thumbnail_to_pil(
                self.image_resources.get_data('THUMBNAIL_RESOURCE_PS4'), 'BGR'
            )
        return None
418003
def _text_image(page):
    
    img = None
    alt = page.data.get('label') or page.data.get('title')
    source = _image(page)
    if source:
        img = "![%s](%s)" % (alt, source)
    return img
948183
def get_thumbnail(self, width, height):
        
        # get from the file
        thumb_path = self._get_thumb_path()
        try:
            doc_file_path = self.get_doc_file_path()

            if (self.fs.exists(thumb_path) and
                    self.fs.getmtime(doc_file_path) <
                    self.fs.getmtime(thumb_path)):
                with self.fs.open(thumb_path, 'rb') as fd:
                    thumbnail = PIL.Image.open(fd)
                    thumbnail.load()
                if thumbnail.size[0] == width or thumbnail.size[1] == height:
                    # fills the specified area
                    return thumbnail
                logger.warning(
                    "[%s] Unexpected thumbnail size: %s instead of %s ;"
                    " Updating thumbnail ...",
                    str(self.doc.docid), str(thumbnail.size),
                    str((width, height))
                )
        except Exception as exc:
            logger.warning(
                "[%s] Failed to check doc and thumbnail mdate. Forcing update"
                " of the thumbnail", str(self.doc.docid), exc_info=exc
            )

        logger.info("[%s] Updating thumbnail ...", str(self.doc.docid))
        thumbnail = self.__make_thumbnail(width, height)
        with self.fs.open(thumb_path, 'wb') as fd:
            thumbnail.save(fd, format="JPEG")

        return thumbnail
980494
def get_image(self, digest, blob, mime_type, index, size=500):
        """"""
        # Special case, for now (XXX).
        if mime_type.startswith("image/"):
            return ""

        cache_key = f"img:{index}:{size}:{digest}"
        return self.cache.get(cache_key)
20299
def thumbnail(self):
        """"""

        if self.filetype not in ("video", "image", "audio"):
            raise RuntimeError("Only video, audio and image files can have thumbnails")
        thumb_srv = self.thumb.get("server")
        url = f"https://{thumb_srv}" if thumb_srv else None
        return f"{url}/asset/{self.fid}/thumb" if url else ""
564504
def thumb(self, obj):
        
        format, created = Format.objects.get_or_create(name='newman_thumb',
                                                       defaults={
            'max_width': 100,
            'max_height': 100,
            'flexible_height': False,
            'stretch': False,
            'nocrop': True,
        })

        if created:
            format.sites = Site.objects.all()

        info = obj.get_formated_photo(format)

        return '<a href="%(href)s"><img src="%(src)s"></a>' % {
            'href': '%s/' % obj.pk,
            'src': info['url']
        }
94753
def get_image(cls, url):
        
        from PIL.ImageFile import Parser as PILParser

        length = 0
        raw_image = None
        with closing(request.get(url, stream=True)) as response:
            response.raise_for_status()
            response_url = response.url
            parser = PILParser()
            for chunk in response.iter_content(config.CHUNK_SIZE):
                length += len(chunk)
                if length > config.IMAGE_MAX_BYTESIZE:
                    del parser
                    raise cls.MaxBytesException
                parser.feed(chunk)
                # comment this to get the whole file
                if parser.image and parser.image.size:
                    raw_image = parser.image
                    del parser # free some memory
                    break
            # or this to get just the size and format
            # raw_image = parser.close()
        if length == 0:
            raise cls.ZeroBytesException
        if not raw_image:
            raise cls.NoImageException
        image = Image(response_url, raw_image.size, raw_image.format)
        return image
298086
def get_large_image(self, page=1):
        
        url = self.get_large_image_url(page=page)
        return self._get_url(url)
1298777
function(res) {
      // handle thumbnail
      var picurl = '';
      // TODO: further process to thumbnail according to its size
      if (!res.thumbnail) {
        // if no thumbnail exists, a default pic should be returned.
        picurl = this.conf.CONST.PIC_PLACEHOLDER;
      } else {
        picurl = res.thumbnail.source;
      }
      res.extract = _.trunc(res.extract, {
        'length': this.conf.CONST.EXTRACT_REPLY_LIMIT, 
        'separator': /(，|。|\n)/
      });
      return {
        title: res.title,
        description: res.extract,
        url: this._page_url(res.title),
        picurl: picurl
      };
    }
109695
def render_thumbnail_tag(document, image_options = {}, url_options = {})
      link_to image_tag(thumbnail_url(document)), url_for_document(document)
    end
923436
def get_thumbnail_image_url(self, page=1):
        
        template = self.resources.page.get('image')
        return template.replace(
            "{page}",
            str(page)
        ).replace("{size}", "thumbnail")
601752
def get_extension(media):
    """"""

    # Photos are always compressed as .jpg by Telegram
    if isinstance(media, (types.UserProfilePhoto,
                          types.ChatPhoto, types.MessageMediaPhoto)):
        return '.jpg'

    # Documents will come with a mime type
    if isinstance(media, types.MessageMediaDocument):
        media = media.document
    if isinstance(media, (
            types.Document, types.WebDocument, types.WebDocumentNoProxy)):
        if media.mime_type == 'application/octet-stream':
            # Octet stream are just bytes, which have no default extension
            return ''
        else:
            return guess_extension(media.mime_type) or ''

    return ''
176840
def picture_url_options
      return {} if picture.nil?

      {
        format: picture.default_render_format,
        crop_from: crop_from.presence,
        crop_size: crop_size.presence
      }.with_indifferent_access
    end
1145578
def documentCover(self):
        
        rels_pth = os.path.join(self._cache_dir, "_rels", ".rels")
        rels_xml = lxml.etree.parse(xmlFile(rels_pth, 'rb'))
        thumb_ns = ns_map["thumbnails"]
        thumb_elm_xpr = "relationships:Relationship[@Type='%s']" % thumb_ns
        rels_xpath = lxml.etree.XPath(thumb_elm_xpr, namespaces=ns_map)
        try:
            cover_path = rels_xpath(rels_xml)[0].attrib["Target"]
        except IndexError:
            return None
        cover_fp = open(self._cache_dir + os.sep + cover_path, "rb")
        cover_type = imghdr.what(None, h=cover_fp.read(32))
        cover_fp.seek(0)
        # some MS docs say the type can be JPEG which is ok,
        # or WMF, which imghdr does not recognize...
        if not cover_type:
            cover_type = cover_path.split('.')[-1]
        else:
            cover_type = cover_type.replace("jpeg", "jpg")
        return (cover_type, cover_fp)
289202
def thumbnail_image(realfile, filename, size=(200, 75), suffix=True, quality=None):
    
    from PIL import Image

    im = Image.open(realfile)
    file, ext = os.path.splitext(realfile)
    if im.size[0]<=size[0] and im.size[1]<=size[1]:
        #the image size is smaller than thumbnail size, so we don't need to 
        #thumbnail the image
        return filename, filename
    im.thumbnail(size, Image.ANTIALIAS)
    format = ext[1:].upper()
    if format == 'JPG':
        format = 'JPEG'
    if suffix:
        ofile = file + ".thumbnail" + ext
    else:
        ofile = realfile
    im.save(ofile, format, quality=quality or QUALITY)
    file1, ext1 = os.path.splitext(filename)
    if suffix:
        ofile1 = file1 + ".thumbnail" + ext
    else:
        ofile1 = filename
    return ofile, ofile1