3 from urllib.request import urlopen
5 from .base import Widget
8 class Background(Widget):
13 if self.cover.book_info.cover_url:
16 data = io.BytesIO(urlopen(self.cover.book_info.cover_url, timeout=3).read())
22 img = PIL.Image.open(data)
25 if img.size[1] > img.size[0]:
26 img = img.crop((0, 0, img.size[0], img.size[0]))
28 left = round((img.size[0] - img.size[1])/2)
37 def build(self, w, h):
40 kwadrat = round(max(w, h))
42 img = self.img.resize((kwadrat, kwadrat))
44 int((img.size[0] - w) / 2),
46 w + int((img.size[0] - w) / 2),