From 2581d16fd69c88618687695186ada5f4f903ea87 Mon Sep 17 00:00:00 2001 From: rupor Date: Thu, 1 Jun 2017 19:00:40 -0400 Subject: [PATCH] Fixing cover and png transparency image processing for books with image links without file extensions --- fb2mobi.config | 2 +- modules/fb2html.py | 16 ++++++++++------ version.py | 2 +- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/fb2mobi.config b/fb2mobi.config index cfe9809..81710fa 100644 --- a/fb2mobi.config +++ b/fb2mobi.config @@ -42,7 +42,7 @@ True True True - False + True eink diff --git a/modules/fb2html.py b/modules/fb2html.py index 84b3139..13dcb5e 100644 --- a/modules/fb2html.py +++ b/modules/fb2html.py @@ -10,6 +10,7 @@ import base64 import hashlib import html +import imghdr from copy import deepcopy from lxml import etree, objectify @@ -348,12 +349,13 @@ def replace_url(url): def remove_png_transparency(self): self.log.info('Removing PNG transparency...') for img_rel_path in self.image_file_list: - if os.path.splitext(img_rel_path)[1] == '.png': - self.log.debug('Processing file "{}"'.format(img_rel_path)) + filename = os.path.split(img_rel_path)[1] + img_full_path = os.path.join(self.temp_content_dir, 'images', filename) + + if imghdr.what(img_full_path) == 'png': + self.log.debug('Processing file "{}"'.format(img_rel_path)) try: - filename = os.path.split(img_rel_path)[1] - img_full_path = os.path.join(self.temp_content_dir, 'images', filename) img = Image.open(img_full_path) if img.format == 'PNG' and (img.mode in ('RGBA', 'LA') or (img.mode in ('RGB', 'L', 'P') and 'transparency' in img.info)): @@ -525,7 +527,10 @@ def parse_description(self, elem): if ns_tag(c.tag) == 'image': for a in c.attrib: if ns_tag(a) == 'href': - self.book_cover = 'images/' + c.attrib[a][1:] + image = c.attrib[a][1:] + if not os.path.splitext(image)[1]: + image += '.jpg' + self.book_cover = 'images/' + image break elif ns_tag(t.tag) == 'genre': @@ -1182,7 +1187,6 @@ def generate_container(self): def generate_cover(self): if self.book_cover: - # make sure kindlegen does not complain on cover size and make sure that epub cover takes whole screen im = Image.open(os.path.join(self.temp_content_dir, self.book_cover)) if im.height < self.screen_height: diff --git a/version.py b/version.py index 7b70627..1553e65 100644 --- a/version.py +++ b/version.py @@ -4,4 +4,4 @@ WINDOWS = platform.system().lower() == "windows" -VERSION = u'3.6.23' +VERSION = u'3.6.24'