3 from ..base import WLElement
6 class Ilustr(WLElement):
7 EPUB_TAG = HTML_TAG = 'img'
9 def get_html_attr(self, builder):
12 url = six.moves.urllib.parse.urljoin(
17 imgfile = six.moves.urllib.request.urlopen(url)
18 img = Image.open(imgfile)
19 th_format, ext, media_type = {
20 'GIF': ('GIF', 'gif', 'image/gif'),
21 'PNG': ('PNG', 'png', 'image/png'),
22 }.get(img.format, ('JPEG', 'jpg', 'image/jpeg'))
25 if img.size[0] < width:
28 th = img.resize((width, round(width * img.size[1] / img.size[0])))
31 buffer = six.BytesIO()
32 th.save(buffer, format=th_format)
34 file_name = 'image%d.%s' % (
35 builder.assign_image_number(),
40 content=buffer.getvalue(),
42 media_type=media_type,
47 'alt': self.attrib['alt'],
48 'title': self.attrib['alt'],
51 get_epub_attr = get_html_attr