fnp
/
librarian.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
bit longer author field
[librarian.git]
/
src
/
librarian
/
elements
/
figures
/
ilustr.py
diff --git
a/src/librarian/elements/figures/ilustr.py
b/src/librarian/elements/figures/ilustr.py
index
ab7c2b7
..
33099f6
100644
(file)
--- a/
src/librarian/elements/figures/ilustr.py
+++ b/
src/librarian/elements/figures/ilustr.py
@@
-1,20
+1,27
@@
-import six.moves
+# This file is part of Librarian, licensed under GNU Affero GPLv3 or later.
+# Copyright © Fundacja Wolne Lektury. See NOTICE for more information.
+#
+import io
+import urllib.parse
+import urllib.request
from PIL import Image
from ..base import WLElement
class Ilustr(WLElement):
from PIL import Image
from ..base import WLElement
class Ilustr(WLElement):
+ SHOULD_HAVE_ID = True
+
EPUB_TAG = HTML_TAG = 'img'
def get_html_attr(self, builder):
## TODO: thumbnail.
EPUB_TAG = HTML_TAG = 'img'
def get_html_attr(self, builder):
## TODO: thumbnail.
- url =
six.moves.
urllib.parse.urljoin(
+ url = urllib.parse.urljoin(
builder.base_url,
self.get('src')
)
builder.base_url,
self.get('src')
)
- imgfile =
six.moves.
urllib.request.urlopen(url)
+ imgfile = urllib.request.urlopen(url)
img = Image.open(imgfile)
th_format, ext, media_type = {
'GIF': ('GIF', 'gif', 'image/gif'),
img = Image.open(imgfile)
th_format, ext, media_type = {
'GIF': ('GIF', 'gif', 'image/gif'),
@@
-27,10
+34,9
@@
class Ilustr(WLElement):
else:
th = img.resize((width, round(width * img.size[1] / img.size[0])))
else:
th = img.resize((width, round(width * img.size[1] / img.size[0])))
- imgfile.close()
- buffer = six.BytesIO()
+ buffer = io.BytesIO()
th.save(buffer, format=th_format)
th.save(buffer, format=th_format)
- ## TODO: Counter
+ imgfile.close()
file_name = 'image%d.%s' % (
builder.assign_image_number(),
ext
file_name = 'image%d.%s' % (
builder.assign_image_number(),
ext
@@
-44,8
+50,8
@@
class Ilustr(WLElement):
return {
'src': file_name,
return {
'src': file_name,
- 'alt': self.attrib
['alt']
,
- 'title': self.attrib
['alt']
,
+ 'alt': self.attrib
.get('alt', '')
,
+ 'title': self.attrib
.get('alt', '')
,
}
get_epub_attr = get_html_attr
}
get_epub_attr = get_html_attr