mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Implement method to add borders to image
This commit is contained in:
parent
60369e8677
commit
989f07901e
@ -161,6 +161,19 @@ def create_text_arc(text, font_size, font=None, bgcolor='white'):
|
||||
p.MagickTrimImage(canvas, 0)
|
||||
return canvas
|
||||
|
||||
def add_borders_to_image(path_to_image, left=0, top=0, right=0, bottom=0,
|
||||
border_color='white'):
|
||||
with p.ImageMagick():
|
||||
img = load_image(path_to_image)
|
||||
lwidth = p.MagickGetImageWidth(img)
|
||||
lheight = p.MagickGetImageHeight(img)
|
||||
canvas = create_canvas(lwidth+left+right, lheight+top+bottom,
|
||||
border_color)
|
||||
compose_image(canvas, img, left, top)
|
||||
p.DestroyMagickWand(img)
|
||||
with open(path_to_image, 'wb') as f:
|
||||
p.MagickWriteImage(canvas, f)
|
||||
p.DestroyMagickWand(canvas)
|
||||
|
||||
def create_cover_page(top_lines, logo_path, width=590, height=750,
|
||||
bgcolor='white', output_format='png'):
|
||||
|
Loading…
x
Reference in New Issue
Block a user