rel_path = ilustr.attrib['src']
img_url = six.moves.urllib.parse.urljoin(base_url, rel_path)
- with six.moves.urllib.request.urlopen(img_url) as f:
- img = Image.open(f)
-
+ f = six.moves.urllib.request.urlopen(img_url)
+ img = Image.open(f)
ext = {'GIF': 'gif', 'PNG': 'png'}.get(img.format, 'jpg')
srcset = []
]
largest = None
for w in widths:
- height = round(img.size[1] * w / img.size[0])
- th = img.resize((w, height))
fname = '%d.W%d.%s' % (i, w, ext)
- th.save(gallery_path + fname)
+ fpath = gallery_path + fname
+ if not os.path.exists(fpath):
+ height = round(img.size[1] * w / img.size[0])
+ th = img.resize((w, height))
+ th.save(fpath)
th_url = gallery_url + fname
srcset.append(" ".join((
th_url,
ilustr.attrib['srcset'] = ", ".join(srcset)
ilustr.attrib['src'] = largest_url
+ f.close()
+
def transform(wldoc, stylesheet='legacy', options=None, flags=None, css=None, gallery_path='img/', gallery_url='img/', base_url='file://./'):
"""Transforms the WL document to XHTML.
document.clean_ed_note()
document.clean_ed_note('abstrakt')
-
+ document.fix_pa_akap()
+
if not options:
options = {}
)
or e.get('id') == 'nota_red'
or e.tag == 'blockquote'
+ or e.get('id') == 'footnotes'
)
if any_ancestor(element, f):
continue