X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/fe8e5b5e224d32baebbdaa2fecf4a847ed4e5354..3b0b98465bc1862306b05bb8305a1abbf40ca310:/librarian/cover.py diff --git a/librarian/cover.py b/librarian/cover.py index b53de30..2320f19 100644 --- a/librarian/cover.py +++ b/librarian/cover.py @@ -4,7 +4,7 @@ # Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information. # import re -import Image, ImageFont, ImageDraw, ImageFilter +from PIL import Image, ImageFont, ImageDraw, ImageFilter from StringIO import StringIO from librarian import get_resource, IOFile @@ -113,15 +113,18 @@ class Cover(object): exts = { 'JPEG': 'jpg', 'PNG': 'png', - } + } mime_types = { 'JPEG': 'image/jpeg', 'PNG': 'image/png', - } + } def __init__(self, book_info, format=None): - self.author = ", ".join(auth.readable() for auth in book_info.authors) + try: + self.author = ", ".join(auth.readable() for auth in book_info.authors) + except AttributeError: + self.author = "" self.title = book_info.title if format is not None: self.format = format @@ -151,24 +154,22 @@ class Cover(object): top = self.author_top tbox = TextBox( self.width - self.author_margin_left - self.author_margin_right, - self.height - top, - ) + self.height - top) author_font = self.author_font or ImageFont.truetype( get_resource('fonts/DejaVuSerif.ttf'), 30) tbox.text(self.pretty_author(), self.author_color, author_font, - self.author_lineskip, self.author_shadow) + self.author_lineskip, self.author_shadow) text_img = tbox.image() img.paste(text_img, (self.author_margin_left, top), text_img) top += text_img.size[1] + self.title_top tbox = TextBox( self.width - self.title_margin_left - self.title_margin_right, - self.height - top, - ) + self.height - top) title_font = self.author_font or ImageFont.truetype( get_resource('fonts/DejaVuSerif.ttf'), 40) tbox.text(self.pretty_title(), self.title_color, title_font, - self.title_lineskip, self.title_shadow) + self.title_lineskip, self.title_shadow) text_img = tbox.image() img.paste(text_img, (self.title_margin_left, top), text_img)