当前位置: 首页>>代码示例>>Python>>正文


Python Image.MIME属性代码示例

本文整理汇总了Python中PIL.Image.MIME属性的典型用法代码示例。如果您正苦于以下问题:Python Image.MIME属性的具体用法?Python Image.MIME怎么用?Python Image.MIME使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在PIL.Image的用法示例。


在下文中一共展示了Image.MIME属性的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: api_v1_coverart_song

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import MIME [as 别名]
def api_v1_coverart_song(songID):
    songs = getSongs(songID=songID)
    if not songs:
        abort(404)
    song = songs[0]
    print('Delivering coverart of song %s: %s' % (songID, song.path()))
    coverart = song.getCoverImage()
    if isinstance(coverart, str):
        return send_file(coverart)
    elif isinstance(coverart, tuple):
        image, data = coverart
        response = Response(data, status=200)
        return response
    elif isinstance(coverart, Image.Image):
        data = coverart.tobytes()
        mime = Image.MIME[coverart.format]
        response = Response(data, status=200, mimetype=mime)
        response.headers["Content-Type"] = mime
        return response

    return '' 
开发者ID:antlarr,项目名称:bard,代码行数:23,代码来源:web.py

示例2: get_image

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import MIME [as 别名]
def get_image(request):

    map_form = MapForm(request.GET)
    if not map_form.is_valid():
        return HttpResponse(json.dumps(map_form.errors), mimetype='application/json', status=400)

    image_data = cached_get_image(**map_form.cleaned_data)

    format = map_form.cleaned_data['format'].upper()
    if format not in Image.MIME:
        raise ValidationError("Unsupported format: %s" % format)
    return HttpResponse(image_data, mimetype=Image.MIME[format]) 
开发者ID:benbacardi,项目名称:tyler,代码行数:14,代码来源:views.py

示例3: parse_binary

# 需要导入模块: from PIL import Image [as 别名]
# 或者: from PIL.Image import MIME [as 别名]
def parse_binary(self, elem):
        if 'id' in elem.attrib:
            self.log.debug('Parsing binary {0}'.format(elem.attrib))
            have_file = False
            elid = elem.attrib['id']
            decl_type = elem.attrib['content-type'].lower() if 'content-type' in elem.attrib else '---empty---'
            buff = base64.b64decode(elem.text.encode('ascii'))
            try:
                img = Image.open(io.BytesIO(buff))
                real_type = Image.MIME[img.format]
                imgfmt = img.format.lower()
                filename = "bin{0:08}.{1}".format(self.image_count, imgfmt.lower().replace('jpeg', 'jpg'))
                full_name = os.path.join(os.path.join(self.temp_content_dir, 'images'), filename)
                make_dir(full_name)

                if self.kindle and not imgfmt in ('gif', 'jpeg', 'png', 'bmp'):
                    self.log.warning('Image type "{0}" for ref-id "{1} is not supported by your device. Ignoring...'.format(real_type, elid))
                    return

                if real_type != decl_type:
                    self.log.warning('Declared and detected image types for ref-id "{0}" do not match: "{1}" is not "{2}". Using detected type...'.format(elid, decl_type, real_type))

                if self.removepngtransparency and imgfmt == 'png' and (img.mode in ('RGBA', 'LA') or (img.mode in ('RGB', 'L', 'P') and 'transparency' in img.info)):
                    try:
                        self.log.debug('Removing image transparency for ref-id "{0}" in file "{1}"'.format(elid, filename))
                        if img.mode == "P" and isinstance(img.info.get("transparency"), bytes):
                            img = img.convert("RGBA")
                        if img.mode in ("L", "LA"):
                            bg = Image.new("L", img.size, 255)
                        else:
                            bg = Image.new("RGB", img.size, (255, 255, 255))
                        alpha = img.convert("RGBA").split()[-1]
                        bg.paste(img, mask=alpha)
                        bg.save(full_name, dpi=img.info.get("dpi"))
                        have_file = True
                    except:
                        self.log.warning('Unable to remove transparency for ref-id "{0}" in file "{1}"'.format(elid, filename))
                        self.log.debug('Getting details:', exc_info=True)

                self.image_count += 1

            except:
                # Pillow does not recognize SVG files
                if decl_type.split('/')[1].lower() == 'svg':
                    real_type = 'image/svg+xml'
                    filename = "bin{0:08}.svg".format(self.image_count)
                    full_name = os.path.join(os.path.join(self.temp_content_dir, 'images'), filename)
                    self.image_count += 1
                else:
                    self.log.error('Unable to process binary for ref-id "{0}". Skipping...'.format(elid))
                    # self.log.debug('Getting details:', exc_info=True)
                    return

            if not have_file:
                write_file_bin(buff, full_name)

            self.image_file_list.append((elid, real_type, filename)) 
开发者ID:rupor-github,项目名称:fb2mobi,代码行数:59,代码来源:fb2html.py


注:本文中的PIL.Image.MIME属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。