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


Python Image.load方法代码示例

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


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

示例1: browse_icon

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import load [as 别名]
    def browse_icon(self, name='blank.png'):
        cherrypy.response.headers['Content-Type'] = 'image/png'
        cherrypy.response.headers['Last-Modified'] = self.last_modified(self.build_time)

        if not hasattr(self, '__browse_icon_cache__'):
            self.__browse_icon_cache__ = {}
        if name not in self.__browse_icon_cache__:
            if name.startswith('_'):
                name = sanitize_file_name2(name[1:])
                try:
                    with open(os.path.join(config_dir, 'tb_icons', name), 'rb') as f:
                        data = f.read()
                except:
                    raise cherrypy.HTTPError(404, 'no icon named: %r'%name)
            else:
                try:
                    data = I(name, data=True)
                except:
                    raise cherrypy.HTTPError(404, 'no icon named: %r'%name)
            img = Image()
            img.load(data)
            width, height = img.size
            scaled, width, height = fit_image(width, height, 48, 48)
            if scaled:
                img.size = (width, height)

            self.__browse_icon_cache__[name] = img.export('png')
        return self.__browse_icon_cache__[name]
开发者ID:astachecki,项目名称:calibre,代码行数:30,代码来源:browse.py

示例2: extract_raster_image

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import load [as 别名]
def extract_raster_image(wmf_data):
    try:
        wmf, wmf_err = plugins['wmf']
    except KeyError:
        raise Unavailable('libwmf not available on this platform')
    if wmf_err:
        raise Unavailable(wmf_err)

    if iswindows:
        import sys, os
        appdir = sys.app_dir
        if isinstance(appdir, unicode):
            appdir = appdir.encode(filesystem_encoding)
        fdir = os.path.join(appdir, 'wmffonts')
        wmf.set_font_dir(fdir)

    data = ''

    with TemporaryDirectory('wmf2png') as tdir:
        with CurrentDir(tdir):
            wmf.render(wmf_data)

            images = list(sorted(glob.glob('*.png')))
            if not images:
                raise NoRaster('No raster images in WMF')
            data = open(images[0], 'rb').read()

    im = Image()
    im.load(data)
    pw = PixelWand()
    pw.color = '#ffffff'
    im.rotate(pw, 180)

    return im.export('png')
开发者ID:BobPyron,项目名称:calibre,代码行数:36,代码来源:__init__.py

示例3: fb2mlize_images

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import load [as 别名]
    def fb2mlize_images(self):
        '''
        This function uses the self.image_hrefs dictionary mapping. It is populated by the dump_text function.
        '''
        from calibre.ebooks.oeb.base import OEB_RASTER_IMAGES

        images = []
        for item in self.oeb_book.manifest:
            # Don't write the image if it's not referenced in the document's text.
            if item.href not in self.image_hrefs:
                continue
            if item.media_type in OEB_RASTER_IMAGES:
                try:
                    if item.media_type != 'image/jpeg':
                        im = Image()
                        im.load(item.data)
                        im.set_compression_quality(70)
                        imdata = im.export('jpg')
                        raw_data = b64encode(imdata)
                    else:
                        raw_data = b64encode(item.data)
                    # Don't put the encoded image on a single line.
                    data = ''
                    col = 1
                    for char in raw_data:
                        if col == 72:
                            data += '\n'
                            col = 1
                        col += 1
                        data += char
                    images.append('<binary id="%s" content-type="image/jpeg">%s\n</binary>' % (self.image_hrefs[item.href], data))
                except Exception as e:
                    self.log.error('Error: Could not include file %s because '
                        '%s.' % (item.href, e))
        return ''.join(images)
开发者ID:089git,项目名称:calibre,代码行数:37,代码来源:fb2ml.py

示例4: browse_icon

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import load [as 别名]
    def browse_icon(self, name="blank.png"):
        cherrypy.response.headers["Content-Type"] = "image/png"
        cherrypy.response.headers["Last-Modified"] = self.last_modified(self.build_time)

        if not hasattr(self, "__browse_icon_cache__"):
            self.__browse_icon_cache__ = {}
        if name not in self.__browse_icon_cache__:
            if name.startswith("_"):
                name = sanitize_file_name2(name[1:])
                try:
                    with open(os.path.join(config_dir, "tb_icons", name), "rb") as f:
                        data = f.read()
                except:
                    raise cherrypy.HTTPError(404, "no icon named: %r" % name)
            else:
                try:
                    data = I(name, data=True)
                except:
                    raise cherrypy.HTTPError(404, "no icon named: %r" % name)
            img = Image()
            img.load(data)
            width, height = img.size
            scaled, width, height = fit_image(width, height, 48, 48)
            if scaled:
                img.size = (width, height)

            self.__browse_icon_cache__[name] = img.export("png")
        return self.__browse_icon_cache__[name]
开发者ID:GaryMMugford,项目名称:calibre,代码行数:30,代码来源:browse.py

示例5: create_cover

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import load [as 别名]
def create_cover(report, icons=(), cols=5, size=60, padding=8):
    icons = icons or tuple(default_cover_icons(cols))
    rows = int(math.ceil(len(icons) / cols))
    canvas = create_canvas(cols * (size + padding), rows * (size + padding), '#eeeeee')
    y = -size - padding // 2
    x = 0
    for i, icon in enumerate(icons):
        if i % cols == 0:
            y += padding + size
            x = padding // 2
        else:
            x += size + padding
        if report and icon in report.name_map:
            ipath = os.path.join(report.path, report.name_map[icon])
        else:
            ipath = I(icon, allow_user_override=False)
        img = Image()
        with open(ipath, 'rb') as f:
            img.load(f.read())
        scaled, nwidth, nheight = fit_image(img.size[0], img.size[1], size, size)
        img.size = nwidth, nheight
        dx = (size - nwidth) // 2
        canvas.compose(img, x + dx, y)

    return canvas.export('JPEG')
开发者ID:pselle,项目名称:calibre,代码行数:27,代码来源:icon_theme.py

示例6: convert_image

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import load [as 别名]
    def convert_image(url,data,sizes,grayscale,
                      removetrans,imgtype="jpg",background='#ffffff'):
        export = False
        img = Image()
        img.load(data)

        owidth, oheight = img.size
        nwidth, nheight = sizes
        scaled, nwidth, nheight = fit_image(owidth, oheight, nwidth, nheight)
        if scaled:
            img.size = (nwidth, nheight)
            export = True

        if normalize_format_name(img.format) != imgtype:
            export = True

        if removetrans and img.has_transparent_pixels():
            canvas = Image()
            canvas.create_canvas(int(img.size[0]), int(img.size[1]), str(background))
            canvas.compose(img)
            img = canvas
            export = True

        if grayscale and img.type != "GrayscaleType":
            img.type = "GrayscaleType"
            export = True

        if export:
            return (img.export(convtype[imgtype]),imgtype,imagetypes[imgtype])
        else:
            logger.debug("image used unchanged")
            return (data,imgtype,imagetypes[imgtype])
开发者ID:iceshipping,项目名称:FanFicFare,代码行数:34,代码来源:story.py

示例7: _data_to_image

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import load [as 别名]
def _data_to_image(data):
    if isinstance(data, Image):
        img = data
    else:
        img = Image()
        img.load(data)
    return img
开发者ID:Coi-l,项目名称:calibre,代码行数:9,代码来源:draw.py

示例8: convert_image

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import load [as 别名]
    def convert_image(url, data, sizes, grayscale, removetrans, imgtype="jpg", background="#ffffff"):
        export = False
        img = Image()
        img.load(data)

        owidth, oheight = img.size
        nwidth, nheight = sizes
        scaled, nwidth, nheight = fit_image(owidth, oheight, nwidth, nheight)

        if normalize_format_name(img.format) == "gif" and GifInfo(StringIO(data), CHECK_IS_ANIMATED).frameCount > 1:
            raise exceptions.RejectImage("Animated gifs come out purely--not going to use it.")

        if scaled:
            img.size = (nwidth, nheight)
            export = True

        if normalize_format_name(img.format) != imgtype:
            export = True

        if removetrans and img.has_transparent_pixels():
            canvas = Image()
            canvas.create_canvas(int(img.size[0]), int(img.size[1]), unicode(background))
            canvas.compose(img)
            img = canvas
            export = True

        if grayscale and img.type != "GrayscaleType":
            img.type = "GrayscaleType"
            export = True

        if export:
            return (img.export(convtype[imgtype]), imgtype, imagetypes[imgtype])
        else:
            logger.debug("image used unchanged")
            return (data, imgtype, imagetypes[imgtype])
开发者ID:PlushBeaver,项目名称:FanFicFare,代码行数:37,代码来源:story.py

示例9: add_borders_to_image

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import load [as 别名]
def add_borders_to_image(img_data, left=0, top=0, right=0, bottom=0, border_color="#ffffff", fmt="jpg"):
    img = Image()
    img.load(img_data)
    lwidth, lheight = img.size
    canvas = create_canvas(lwidth + left + right, lheight + top + bottom, border_color)
    canvas.compose(img, left, top)
    return canvas.export(fmt)
开发者ID:JapaChin,项目名称:calibre,代码行数:9,代码来源:draw.py

示例10: resize_image

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import load [as 别名]
 def resize_image(self, raw, base, max_width, max_height):
     img = Image()
     img.load(raw)
     resized, nwidth, nheight = fit_image(img.size[0], img.size[1], max_width, max_height)
     if resized:
         img.size = (nwidth, nheight)
         base, ext = os.path.splitext(base)
         base = base + '-%dx%d%s' % (max_width, max_height, ext)
         raw = img.export(ext[1:])
     return raw, base, resized
开发者ID:AEliu,项目名称:calibre,代码行数:12,代码来源:images.py

示例11: check_raster_images

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import load [as 别名]
def check_raster_images(name, mt, raw):
    errors = []
    i = Image()
    try:
        i.load(raw)
    except Exception as e:
        errors.append(InvalidImage(as_unicode(e.message), name))
    else:
        if i.colorspace == 'CMYKColorspace':
            errors.append(CMYKImage(_('Image is in the CMYK colorspace'), name))

    return errors
开发者ID:089git,项目名称:calibre,代码行数:14,代码来源:images.py

示例12: create_cover_page

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import load [as 别名]
def create_cover_page(
    top_lines,
    logo_path,
    width=590,
    height=750,
    bgcolor="#ffffff",
    output_format="jpg",
    texture_data=None,
    texture_opacity=1.0,
):
    """
    Create the standard calibre cover page and return it as a byte string in
    the specified output_format.
    """
    canvas = create_canvas(width, height, bgcolor)
    if texture_data and hasattr(canvas, "texture"):
        texture = Image()
        texture.load(texture_data)
        texture.set_opacity(texture_opacity)
        canvas.texture(texture)

    bottom = 10
    for line in top_lines:
        twand = create_text_wand(line.font_size, font_path=line.font_path)
        bottom = draw_centered_text(canvas, twand, line.text, bottom)
        bottom += line.bottom_margin
    bottom -= top_lines[-1].bottom_margin

    foot_font = P("fonts/liberation/LiberationMono-Regular.ttf")
    vanity = create_text_arc(__appname__ + " " + __version__, 24, font=foot_font, bgcolor="#00000000")
    lwidth, lheight = vanity.size
    left = int(max(0, (width - lwidth) / 2.0))
    top = height - lheight - 10
    canvas.compose(vanity, left, top)

    available = (width, int(top - bottom) - 20)
    if available[1] > 40:
        logo = Image()
        logo.open(logo_path)
        lwidth, lheight = logo.size
        scaled, lwidth, lheight = fit_image(lwidth, lheight, *available)
        if scaled:
            logo.size = (lwidth, lheight)
        left = int(max(0, (width - lwidth) / 2.0))
        top = bottom + 10
        extra = int((available[1] - lheight) / 2.0)
        if extra > 0:
            top += extra
        canvas.compose(logo, left, top)

    return canvas.export(output_format)
开发者ID:JapaChin,项目名称:calibre,代码行数:53,代码来源:draw.py

示例13: identify_data

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import load [as 别名]
def identify_data(data):
    '''
    Identify the image in data. Returns a 3-tuple
    (width, height, format)
    or raises an Exception if data is not an image.
    '''
    img = Image()
    if hasattr(img, 'identify'):
        img.identify(data)
    else:
        img.load(data)
    width, height = img.size
    fmt = img.format
    return (width, height, fmt)
开发者ID:089git,项目名称:calibre,代码行数:16,代码来源:draw.py

示例14: identify_data

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import load [as 别名]
def identify_data(data):
    '''
    Identify the image in data. Returns a 3-tuple
    (width, height, format)
    or raises an Exception if data is not an image.
    '''
    if data.startswith(b'<?xml'):
        # ImageMagick segfaults when trying to identify SVG images
        raise ValueError('Identifying svg images is not supported')
    img = Image()
    if hasattr(img, 'identify'):
        img.identify(data)
    else:
        img.load(data)
    width, height = img.size
    fmt = img.format
    return (width, height, fmt)
开发者ID:AtulKumar2,项目名称:calibre,代码行数:19,代码来源:draw.py

示例15: encode_thumbnail

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import load [as 别名]
def encode_thumbnail(thumbnail):
    '''
    Encode the image part of a thumbnail, then return the 3 part tuple
    '''
    from calibre.utils.magick import Image

    if thumbnail is None:
        return None
    if not isinstance(thumbnail, (tuple, list)):
        try:
            img = Image()
            img.load(thumbnail)
            width, height = img.size
            thumbnail = (width, height, thumbnail)
        except:
            return None
    return (thumbnail[0], thumbnail[1], b64encode(str(thumbnail[2])))
开发者ID:Eksmo,项目名称:calibre,代码行数:19,代码来源:json_codec.py


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