本文整理汇总了Python中calibre.utils.magick.Image.set_opacity方法的典型用法代码示例。如果您正苦于以下问题:Python Image.set_opacity方法的具体用法?Python Image.set_opacity怎么用?Python Image.set_opacity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类calibre.utils.magick.Image
的用法示例。
在下文中一共展示了Image.set_opacity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_cover_page
# 需要导入模块: from calibre.utils.magick import Image [as 别名]
# 或者: from calibre.utils.magick.Image import set_opacity [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)