mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-08-11 09:13:57 -04:00
Cover generation: Scale logo to fit in available space
This commit is contained in:
parent
dd8e6229fc
commit
965413b392
@ -165,12 +165,17 @@ def create_cover_page(top_lines, logo_path, width=590, height=750,
|
||||
top = height - lheight - 10
|
||||
canvas.compose(vanity, left, top)
|
||||
|
||||
logo = Image()
|
||||
logo.open(logo_path)
|
||||
lwidth, lheight = logo.size
|
||||
left = int(max(0, (width - lwidth)/2.))
|
||||
top = max(int((height - lheight)/2.), bottom+20)
|
||||
canvas.compose(logo, 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.))
|
||||
top = bottom+10
|
||||
canvas.compose(logo, left, top)
|
||||
|
||||
return canvas.export(output_format)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user