Cover generation: Scale logo to fit in available space

This commit is contained in:
Kovid Goyal 2010-09-08 12:38:15 -06:00
parent dd8e6229fc
commit 965413b392

View File

@ -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)