798dfaf435572efd4ae05f9cd5c226ea71a92229
[librarian.git] / src / librarian / covers / widgets / image.py
1 # This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
2 # Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
3 #
4 import PIL.Image
5 from librarian import get_resource
6 from .base import Widget
7
8
9 class ImageWidget(Widget):
10     def build(self, w, h):
11         img = PIL.Image.open(self.image_path)
12         img = img.resize((round(img.size[0] / img.size[1] * h), h))
13         return img
14     
15     
16 class WLLogo(ImageWidget):
17     @property
18     def image_path(self):
19         if self.cover.color_scheme['text'] == '#fff':
20             return get_resource('res/cover/logo_WL_invert.png')
21         else:
22             return get_resource('res/cover/logo_WL.png')
23
24
25 class Label(ImageWidget):
26     @property
27     def image_path(self):
28         if self.cover.is_very_bright:
29             return get_resource('res/cover/label_WLpolecaja.szary.png')
30         else:
31             return get_resource('res/cover/label_WLpolecaja.png')
32