+ if cover:
+ cover_file = StringIO()
+ c = cover(book_info.author.readable(), book_info.title)
+ c.save(cover_file)
+ c_name = 'cover.%s' % c.ext()
+ zip.writestr(os.path.join('OPS', c_name), cover_file.getvalue())
+ del cover_file
+
+ cover_tree = etree.parse(get_resource('epub/cover.html'))
+ cover_tree.find('//' + XHTMLNS('img')).set('src', c_name)
+ zip.writestr('OPS/cover.html', etree.tostring(
+ cover_tree, method="html", pretty_print=True))
+
+ manifest.append(etree.fromstring(
+ '<item id="cover" href="cover.html" media-type="application/xhtml+xml" />'))
+ manifest.append(etree.fromstring(
+ '<item id="cover-image" href="%s" media-type="%s" />' % (c_name, c.mime_type())))
+ spine.insert(0, etree.fromstring('<itemref idref="cover" />'))
+ opf.getroot()[0].append(etree.fromstring('<meta name="cover" content="cover-image"/>'))
+ opf.getroot().append(etree.fromstring('<guide><reference href="cover.html" type="cover" title="Okładka"/></guide>'))
+
+