本文整理汇总了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)
示例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
示例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)
示例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])
示例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()