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])))
30 buffer = six.BytesIO()
31 th.save(buffer, format=th_format)
33 file_name = 'image%d.%s' % (
34 builder.assign_image_number(),
39 content=buffer.getvalue(),
41 media_type=media_type,
46 'alt': self.attrib['alt'],
47 'title': self.attrib['alt'],
50 get_epub_attr = get_html_attr