3 from ..base import WLElement
6 class Ilustr(WLElement):
9 EPUB_TAG = HTML_TAG = 'img'
11 def get_html_attr(self, builder):
14 url = six.moves.urllib.parse.urljoin(
19 imgfile = six.moves.urllib.request.urlopen(url)
20 img = Image.open(imgfile)
21 th_format, ext, media_type = {
22 'GIF': ('GIF', 'gif', 'image/gif'),
23 'PNG': ('PNG', 'png', 'image/png'),
24 }.get(img.format, ('JPEG', 'jpg', 'image/jpeg'))
27 if img.size[0] < width:
30 th = img.resize((width, round(width * img.size[1] / img.size[0])))
32 buffer = six.BytesIO()
33 th.save(buffer, format=th_format)
35 file_name = 'image%d.%s' % (
36 builder.assign_image_number(),
41 content=buffer.getvalue(),
43 media_type=media_type,
48 'alt': self.attrib.get('alt', ''),
49 'title': self.attrib.get('alt', ''),
52 get_epub_attr = get_html_attr