3 from urllib.request import urlopen
5 from .base import Widget
8 class Background(Widget):
12 if self.cover.book_info.cover_url:
15 data = io.BytesIO(urlopen(self.cover.book_info.cover_url, timeout=3).read())
21 img = PIL.Image.open(data)
24 if img.size[1] > img.size[0]:
25 img = img.crop((0, 0, img.size[0], img.size[0]))
27 left = round((img.size[0] - img.size[1])/2)
36 def build(self, w, h):
37 kwadrat = round(max(w, h))
39 img = self.img.resize((kwadrat, kwadrat))
41 int((img.size[0] - w) / 2),
43 w + int((img.size[0] - w) / 2),