1 # -*- coding: utf-8 -*-
3 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
4 # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
6 import Image, ImageFont, ImageDraw
7 from librarian import get_resource
10 def cover(width, height, author, title):
11 def draw_centered_text(text, draw, font, width, pos_y, lineskip):
14 while draw.textsize(line, font=font)[0] > width:
16 line, ext = line.rsplit(' ', 1)
19 draw.text(((img.size[0] - draw.textsize(line, font=font)[0]) / 2, pos_y), line, font=font, fill='#000')
21 text = text[len(line)+1:]
25 img = Image.new('RGB', (width, height), (255, 255, 255))
28 logo = Image.open(get_resource('pdf/wl-logo.png'))
29 logo = logo.resize((img.size[0] / 2, logo.size[1] * img.size[0] / 2 / logo.size[0]))
30 img.paste(logo, (width / 4, img.size[1] - logo.size[1]))
32 draw = ImageDraw.Draw(img)
33 author_font = ImageFont.truetype(get_resource('fonts/DejaVuSerif.ttf'), width/20)
34 title_y = draw_centered_text(author, draw, author_font, width*9/10, height/10, width/15) + height/10
36 title_font = ImageFont.truetype(get_resource('fonts/DejaVuSerif.ttf'), width/15)
37 draw_centered_text(title, draw, title_font, width*9/10, title_y, width/11)