- if os.path.isdir(ilustr_path):
- ilustr_elements = set(ilustr.get('src')
- for ilustr in document.edoc.findall('//ilustr'))
- for i, filename in enumerate(os.listdir(ilustr_path)):
- if filename not in ilustr_elements:
- continue
- file_path = os.path.join(ilustr_path, filename)
- with open(file_path, 'rb') as f:
- output.add_item(
- epub.EpubItem(
- uid='image%s' % i,
- file_name=filename,
- media_type=guess_type(file_path)[0],
- content=f.read()
- )
- )
+ # FIXME
+ for i, ilustr in enumerate(document.edoc.findall('//ilustr')):
+ url = six.moves.urllib.parse.urljoin(
+ base_url,
+ ilustr.get('src')
+ )
+ imgfile = six.moves.urllib.request.urlopen(url)
+ img = Image.open(imgfile)
+
+ th_format, ext, media_type = {
+ 'GIF': ('GIF', 'gif', 'image/gif'),
+ 'PNG': ('PNG', 'png', 'image/png'),
+ }.get(img.format, ('JPEG', 'jpg', 'image/jpeg'))
+
+ width = 1200
+ if img.size[0] < width:
+ th = img
+ else:
+ th = img.resize((width, round(width * img.size[1] / img.size[0])))