fnp
/
librarian.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
report images without extensions, allow span.item
[librarian.git]
/
librarian
/
formats
/
cover
/
__init__.py
diff --git
a/librarian/formats/cover/__init__.py
b/librarian/formats/cover/__init__.py
index
b9b515a
..
4788e39
100644
(file)
--- a/
librarian/formats/cover/__init__.py
+++ b/
librarian/formats/cover/__init__.py
@@
-4,9
+4,9
@@
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
import re
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
import re
-from PIL import Image, ImageFont, ImageDraw, ImageFilter
, ImageEnhance
+from PIL import Image, ImageFont, ImageDraw, ImageFilter
from StringIO import StringIO
from StringIO import StringIO
-from librarian import DCNS,
URLOpene
r
+from librarian import DCNS,
BuildErro
r
from librarian.output import OutputFile
from librarian.utils import get_resource
from librarian.formats import Format
from librarian.output import OutputFile
from librarian.utils import get_resource
from librarian.formats import Format
@@
-143,6
+143,7
@@
class Cover(Format):
}
def __init__(self, doc, format=None, width=None, height=None):
}
def __init__(self, doc, format=None, width=None, height=None):
+ super(Cover, self).__init__(doc)
self.author = ", ".join(auth for auth in doc.meta.get(DCNS('creator')))
self.title = doc.meta.title()
if format is not None:
self.author = ", ".join(auth for auth in doc.meta.get(DCNS('creator')))
self.title = doc.meta.title()
if format is not None:
@@
-164,6
+165,9
@@
class Cover(Format):
img = Image.new('RGB', (metr.width, metr.height), self.background_color)
if self.background_img:
img = Image.new('RGB', (metr.width, metr.height), self.background_color)
if self.background_img:
+ IMG_EXT = ('png', 'jpg', 'jpeg')
+ if '.' not in self.background_img or self.background_img.rsplit('.')[1].lower() not in IMG_EXT:
+ raise BuildError('Wrong cover format, should be PNG or JPG')
background = Image.open(self.background_img)
resized = background.resize((1024, background.height*1024/background.width), Image.ANTIALIAS)
resized = resized.convert('RGBA')
background = Image.open(self.background_img)
resized = background.resize((1024, background.height*1024/background.width), Image.ANTIALIAS)
resized = resized.convert('RGBA')
@@
-185,7
+189,8
@@
class Cover(Format):
author_font = ImageFont.truetype(
self.author_font_ttf, metr.author_font_size)
author_font = ImageFont.truetype(
self.author_font_ttf, metr.author_font_size)
- tbox.text(self.pretty_author(), self.author_color, author_font,
+ tbox.text(
+ self.pretty_author(), self.author_color, author_font,
metr.author_lineskip, self.author_shadow)
text_img = tbox.image()
img.paste(text_img, (metr.author_margin_left, top), text_img)
metr.author_lineskip, self.author_shadow)
text_img = tbox.image()
img.paste(text_img, (metr.author_margin_left, top), text_img)
@@
-197,15
+202,16
@@
class Cover(Format):
)
title_font = ImageFont.truetype(
self.title_font_ttf, metr.title_font_size)
)
title_font = ImageFont.truetype(
self.title_font_ttf, metr.title_font_size)
- tbox.text(self.pretty_title(), self.title_color, title_font,
+ tbox.text(
+ self.pretty_title(), self.title_color, title_font,
metr.title_lineskip, self.title_shadow)
text_img = tbox.image()
img.paste(text_img, (metr.title_margin_left, top), text_img)
return img
metr.title_lineskip, self.title_shadow)
text_img = tbox.image()
img.paste(text_img, (metr.title_margin_left, top), text_img)
return img
- imgstr = StringIO()
- img.save(imgstr, format=self.format, quality=95)
-
OutputFile.from_str
ing(imgstr.getvalue())
+
#
imgstr = StringIO()
+
#
img.save(imgstr, format=self.format, quality=95)
+
# OutputFile.from_string
ing(imgstr.getvalue())
def mime_type(self):
return self.mime_types[self.format]
def mime_type(self):
return self.mime_types[self.format]