+ def __init__(self, author='', title=''):
+ self.author = author
+ self.title = title
+
+ def pretty_author(self):
+ return self.author
+
+ def pretty_title(self):
+ return self.title
+
+ def image(self):
+ img = Image.new('RGB', (self.width, self.height), self.background_color)
+
+ if self.background_img:
+ background = Image.open(self.background_img)
+ img.paste(background, None, background)
+ del background
+
+ # WL logo
+ if self.logo_width:
+ logo = Image.open(get_resource('res/wl-logo.png'))
+ logo = logo.resize((self.logo_width, logo.size[1] * self.logo_width / logo.size[0]))
+ img.paste(logo, ((self.width - self.logo_width) / 2, img.size[1] - logo.size[1] - self.logo_bottom))
+
+ author_font = self.author_font or ImageFont.truetype(get_resource('fonts/DejaVuSerif.ttf'), 30)
+ title_y = self.draw_centered_text(self.pretty_author(), img, author_font,
+ self.author_margin_left, self.width - self.author_margin_left - self.author_margin_right, self.author_top,
+ self.author_lineskip, self.author_color, self.author_shadow) + self.title_top
+ title_font = self.title_font or ImageFont.truetype(get_resource('fonts/DejaVuSerif.ttf'), 40)
+ self.draw_centered_text(self.pretty_title(), img, title_font,
+ self.title_margin_left, self.width - self.title_margin_left - self.title_margin_right, title_y,
+ self.title_lineskip, self.title_color, self.title_shadow)
+
+ return img
+
+ def mime_type(self):
+ return self.mime_types[self.format]
+
+ def ext(self):
+ return self.exts[self.format]
+
+ def save(self, *args, **kwargs):
+ return self.image().save(*args, format=self.format, **kwargs)
+
+
+
+class VirtualoCover(Cover):
+ width = 600
+ height = 730
+ author_top = 73
+ title_top = 73
+ logo_bottom = 0
+ logo_width = 300
+
+
+class PrestigioCover(Cover):
+ width = 580
+ height = 783
+ background_img = get_resource('res/cover-prestigio.png')