From: Radek Czajka Date: Fri, 3 Jan 2014 16:01:23 +0000 (+0100) Subject: Use cover with logos by default. X-Git-Tag: 1.7~118 X-Git-Url: https://git.mdrn.pl/librarian.git/commitdiff_plain/5c8dc23489cec14f405a7cf8aef9d68384762571?ds=sidebyside Use cover with logos by default. --- diff --git a/librarian/book2anything.py b/librarian/book2anything.py index b8b8d27..9a246ae 100755 --- a/librarian/book2anything.py +++ b/librarian/book2anything.py @@ -10,7 +10,7 @@ import optparse from librarian import DirDocProvider, ParseError from librarian.parser import WLDocument -from librarian.cover import WLCover +from librarian.cover import DefaultEbookCover class Option(object): @@ -100,10 +100,10 @@ class Book2Anything(object): if cls.uses_cover: if options.image_cache: def cover_class(*args, **kwargs): - return WLCover(image_cache=options.image_cache, *args, **kwargs) + return DefaultEbookCover(image_cache=options.image_cache, *args, **kwargs) transform_args['cover'] = cover_class elif not cls.cover_optional or options.with_cover: - transform_args['cover'] = WLCover + transform_args['cover'] = DefaultEbookCover # Do some real work diff --git a/librarian/cover.py b/librarian/cover.py index 9b10ed1..d1b2cc0 100644 --- a/librarian/cover.py +++ b/librarian/cover.py @@ -125,6 +125,7 @@ class Cover(object): format = 'JPEG' scale = 1 + scale_after = 1 exts = { 'JPEG': 'jpg', @@ -142,8 +143,10 @@ class Cover(object): if format is not None: self.format = format scale = max(float(width or 0) / self.width, float(height or 0) / self.height) - if scale: + if scale >= 1: self.scale = scale + elif scale: + self.scale_after = scale def pretty_author(self): """Allows for decorating author's name.""" @@ -195,6 +198,15 @@ class Cover(object): return img + def final_image(self): + img = self.image() + if self.scale_after != 1: + img = img.resize(( + int(round(img.size[0] * self.scale_after)), + int(round(img.size[1] * self.scale_after))), + Image.ANTIALIAS) + return img + def mime_type(self): return self.mime_types[self.format] @@ -202,7 +214,7 @@ class Cover(object): return self.exts[self.format] def save(self, *args, **kwargs): - return self.image().save(format=self.format, quality=95, *args, **kwargs) + return self.final_image().save(format=self.format, quality=95, *args, **kwargs) def output_file(self, *args, **kwargs): imgstr = StringIO() @@ -211,7 +223,7 @@ class Cover(object): class WLCover(Cover): - """Default Wolne Lektury cover generator.""" + """Wolne Lektury cover without logos.""" width = 600 height = 833 uses_dc_cover = True @@ -483,3 +495,7 @@ class GandalfCover(Cover): logo_bottom = 25 logo_width = 250 format = 'PNG' + + +DefaultEbookCover = LogoWLCover + diff --git a/librarian/epub.py b/librarian/epub.py index bfd7570..2da6b31 100644 --- a/librarian/epub.py +++ b/librarian/epub.py @@ -17,7 +17,7 @@ from tempfile import mkdtemp, NamedTemporaryFile from shutil import rmtree from librarian import RDFNS, WLNS, NCXNS, OPFNS, XHTMLNS, OutputFile -from librarian.cover import WLCover +from librarian.cover import DefaultEbookCover from librarian import functions, get_resource @@ -448,7 +448,7 @@ def transform(wldoc, verbose=False, if cover: if cover is True: - cover = WLCover + cover = DefaultEbookCover cover_file = StringIO() bound_cover = cover(document.book_info) diff --git a/librarian/mobi.py b/librarian/mobi.py index d98b838..74018b3 100644 --- a/librarian/mobi.py +++ b/librarian/mobi.py @@ -9,7 +9,7 @@ import subprocess from tempfile import NamedTemporaryFile from librarian import OutputFile -from librarian.cover import WLCover +from librarian.cover import DefaultEbookCover from librarian import get_resource @@ -29,7 +29,7 @@ def transform(wldoc, verbose=False, # provide a cover by default if not cover: - cover = WLCover + cover = DefaultEbookCover cover_file = NamedTemporaryFile(suffix='.png', delete=False) bound_cover = cover(book_info) bound_cover.save(cover_file) @@ -57,4 +57,4 @@ def transform(wldoc, verbose=False, subprocess.check_call(['ebook-convert', epub.get_filename(), output_file.name, '--no-inline-toc', '--cover=%s' % cover_file.name], **kwargs) os.unlink(cover_file.name) - return OutputFile.from_filename(output_file.name) \ No newline at end of file + return OutputFile.from_filename(output_file.name) diff --git a/librarian/parser.py b/librarian/parser.py index a9e8c65..e06c4d7 100644 --- a/librarian/parser.py +++ b/librarian/parser.py @@ -5,7 +5,7 @@ # from librarian import ValidationError, NoDublinCore, ParseError, NoProvider from librarian import RDFNS -from librarian.cover import WLCover +from librarian.cover import DefaultEbookCover from librarian import dcparser from xml.parsers.expat import ExpatError @@ -208,7 +208,7 @@ class WLDocument(object): def as_cover(self, cover_class=None, *args, **kwargs): if cover_class is None: - cover_class = WLCover + cover_class = DefaultEbookCover return cover_class(self.book_info, *args, **kwargs).output_file() def save_output_file(self, output_file, output_path=None, diff --git a/librarian/pdf.py b/librarian/pdf.py index b4edfdb..2154985 100644 --- a/librarian/pdf.py +++ b/librarian/pdf.py @@ -27,7 +27,7 @@ from librarian.dcparser import Person from librarian.parser import WLDocument from librarian import ParseError, DCNS, get_resource, OutputFile from librarian import functions -from librarian.cover import WLCover +from librarian.cover import DefaultEbookCover functions.reg_substitute_entities() @@ -204,7 +204,7 @@ def transform(wldoc, verbose=False, save_tex=None, morefloats=None, if cover: if cover is True: - cover = WLCover + cover = DefaultEbookCover bound_cover = cover(book_info) root.set('data-cover-width', str(bound_cover.width)) root.set('data-cover-height', str(bound_cover.height))