X-Git-Url: https://git.mdrn.pl/librarian.git/blobdiff_plain/adfc9d2b19ec27d32d5e4dd3ceba16d1fe51fcc9..7805246da7d634d97dfa9e864c2502bd56a3a919:/src/librarian/cover.py?ds=sidebyside diff --git a/src/librarian/cover.py b/src/librarian/cover.py index 5e397c4..dfb0b76 100644 --- a/src/librarian/cover.py +++ b/src/librarian/cover.py @@ -289,6 +289,7 @@ class WLCover(Cover): background_color = '#444' author_color = '#444' background_img = get_resource('res/cover.png') + background_top = False format = 'JPEG' epoch_colors = { @@ -322,11 +323,10 @@ class WLCover(Cover): self.bar_width = 0 else: self.bar_color = book_info.cover_bar_color or \ - self.epoch_colors.get(book_info.epoch, self.bar_color) + self.get_variable_color(book_info) or self.bar_color # Set title color. if self.set_title_color: - self.title_color = self.epoch_colors.get(book_info.epoch, - self.title_color) + self.title_color = self.get_variable_color(book_info) or self.title_color self.bleed = bleed self.box_top_margin += bleed @@ -341,6 +341,9 @@ class WLCover(Cover): self.background_img = BytesIO(bg_src.read()) bg_src.close() + def get_variable_color(self, book_info): + return self.epoch_colors.get(book_info.epoch, None) + def pretty_authors(self): return [a.upper() for a in self.authors] @@ -476,7 +479,10 @@ class WLCover(Cover): trg_size[0], int(round(src.size[1] * trg_size[0] / src.size[0])) ) - cut = (resized[1] - trg_size[1]) // 2 + if self.background_top: + cut = 0 + else: + cut = (resized[1] - trg_size[1]) // 2 src = src.resize(resized, Image.ANTIALIAS) src = src.crop((0, cut, src.size[0], src.size[1] - cut)) else: @@ -731,16 +737,49 @@ class LegimiCover(LogoWLCover): ] logos_right = False gradient_logo_centering = True + background_top = True + + genre_colors = { + 'Artykuł': '#bf001a', + 'Artykuł naukowy': '#bf001a', + 'Dziennik': '#bf001a', + 'Esej': '#bf001a', + 'Felieton': '#bf001a', + 'Kronika': '#bf001a', + 'List': '#bf001a', + 'Manifest': '#bf001a', + 'Odczyt': '#bf001a', + 'Pamiętnik': '#bf001a', + 'Poradnik': '#bf001a', + 'Praca naukowa': '#bf001a', + 'Publicystyka': '#bf001a', + 'Reportaż': '#bf001a', + 'Reportaż podróżniczy': '#bf001a', + 'Rozprawa': '#bf001a', + 'Rozprawa polityczna': '#bf001a', + 'Traktat': '#bf001a', + } + kind_colors = { + 'Epika': '#9bbb2b', + 'Liryka': '#3e626f', + 'Dramat': '#ecbe00', + } def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) if self.has_gradient_logos: self.box_bottom_margin += self.box_bottom_margin_logos_add - - + def pretty_authors(self): return self.authors + def get_variable_color(self, book_info): + for genre in book_info.genres: + if genre in self.genre_colors: + return self.genre_colors[genre] + for kind in book_info.kinds: + if kind in self.kind_colors: + return self.kind_colors[kind] class LegimiCornerCover(LegimiCover): gradient_logos = []