Skip to content
This repository has been archived by the owner on Mar 15, 2020. It is now read-only.

Commit

Permalink
Fixing cover and png transparency image processing for books with ima…
Browse files Browse the repository at this point in the history
…ge links without file extensions
  • Loading branch information
rupor-github committed Jun 1, 2017
1 parent 95a697a commit 2581d16
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion fb2mobi.config
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
<generateAnnotationPage>True</generateAnnotationPage>
<generateOPFGuide>True</generateOPFGuide>
<kindleRemovePersonalLabel>True</kindleRemovePersonalLabel>
<removePngTransparency>False</removePngTransparency>
<removePngTransparency>True</removePngTransparency>
<generateAPNX>eink</generateAPNX>
<vignettes>
<vignette level="default">
Expand Down
16 changes: 10 additions & 6 deletions modules/fb2html.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import base64
import hashlib
import html
import imghdr

from copy import deepcopy
from lxml import etree, objectify
Expand Down Expand Up @@ -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)):
Expand Down Expand Up @@ -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':
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

WINDOWS = platform.system().lower() == "windows"

VERSION = u'3.6.23'
VERSION = u'3.6.24'

0 comments on commit 2581d16

Please sign in to comment.