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 top = height - lheight - 10
canvas.compose(vanity, left, top) canvas.compose(vanity, left, top)
logo = Image() available = (width, int(top - bottom)-20)
logo.open(logo_path) if available[1] > 40:
lwidth, lheight = logo.size logo = Image()
left = int(max(0, (width - lwidth)/2.)) logo.open(logo_path)
top = max(int((height - lheight)/2.), bottom+20) lwidth, lheight = logo.size
canvas.compose(logo, left, top) 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) return canvas.export(output_format)