2 from urllib.request import urlopen
4 from .base import Widget
7 class Background(Widget):
11 if self.cover.book_info.cover_url:
14 data = io.BytesIO(urlopen(self.cover.book_info.cover_url, timeout=3).read())
20 img = PIL.Image.open(data)
23 if img.size[1] > img.size[0]:
24 img = img.crop((0, 0, img.size[0], img.size[0]))
26 left = round((img.size[0] - img.size[1])/2)
35 def build(self, w, h):
36 kwadrat = round(max(w, h))
38 img = self.img.resize((kwadrat, kwadrat))
40 int((img.size[0] - w) / 2),
42 w + int((img.size[0] - w) / 2),