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


Python Image.open方法代码示例

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


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

示例1: flip_image

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import open [as 别名]
def flip_image(img, flip):
    from calibre.utils.magick import Image
    im = Image()
    im.open(img)
    if b'x' in flip:
        im.flip(True)
    if b'y' in flip:
        im.flip()
    im.save(img)
开发者ID:miheerdew,项目名称:calibre,代码行数:11,代码来源:pdftohtml.py

示例2: postprocess_html

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import open [as 别名]
 def postprocess_html(self, soup, first):
     #process all the images
     for tag in soup.findAll(lambda tag: tag.name.lower()=='img' and tag.has_key('src')):
         iurl = tag['src']
         img = Image()
         img.open(iurl)
         if img < 0:
             raise RuntimeError('Out of memory')
         img.type = "GrayscaleType"
         img.save(iurl)
     return soup
开发者ID:arpan-chavda,项目名称:calibre_recipes,代码行数:13,代码来源:Seniors'+Blog_1003.py

示例3: create_cover_page

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import open [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

示例4: convert_image

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

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

            if normalize_format_name(img.format) != imgtype:
                if img.mode == "P":
                    # convert pallete gifs to RGB so jpg save doesn't fail.
                    img = img.convert("RGB")
                export = True

            if removetrans and img.mode == "RGBA":
                background = Image.new("RGBA", img.size, background)
                # Paste the image on top of the background
                background.paste(img, img)
                img = background.convert("RGB")
                export = True

            if grayscale and img.mode != "L":
                img = img.convert("L")
                export = True

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

示例5: render

# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import open [as 别名]
 def render(self):
     from calibre.utils.magick import Image
     img = Image()
     img.open(self.path_to_page)
     width, height = img.size
     if self.num == 0:  # First image so create a thumbnail from it
         thumb = img.clone
         thumb.thumbnail(60, 80)
         thumb.save(os.path.join(self.dest, 'thumbnail.png'))
     self.pages = [img]
     if width > height:
         if self.opts.landscape:
             self.rotate = True
         else:
             split1, split2 = img.clone, img.clone
             half = int(width/2)
             split1.crop(half-1, height, 0, 0)
             split2.crop(half-1, height, half, 0)
             self.pages = [split2, split1] if self.opts.right2left else [split1, split2]
     self.process_pages()
开发者ID:089git,项目名称:calibre,代码行数:22,代码来源:input.py


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