From a9b3adbad343919181e227dd0d235c31e1503385 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 25 Jan 2014 09:52:36 +0530 Subject: [PATCH] Edit Book: Fix extra 1x1 unused GIF image being created when saving and re-opening AZW3 files. Fixes #1272410 [Editing AZW3 book adds 1x1 pixel gray gif each time](https://bugs.launchpad.net/calibre/+bug/1272410) --- src/calibre/ebooks/mobi/reader/mobi8.py | 3 +++ src/calibre/ebooks/mobi/writer2/resources.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/calibre/ebooks/mobi/reader/mobi8.py b/src/calibre/ebooks/mobi/reader/mobi8.py index 6536c92618..734ba17abe 100644 --- a/src/calibre/ebooks/mobi/reader/mobi8.py +++ b/src/calibre/ebooks/mobi/reader/mobi8.py @@ -386,6 +386,7 @@ class Mobi8Reader(object): return build_toc(index_entries) def extract_resources(self): + from calibre.ebooks.mobi.writer2.resources import PLACEHOLDER_GIF resource_map = [] for x in ('fonts', 'images'): os.mkdir(x) @@ -414,6 +415,8 @@ class Mobi8Reader(object): if font['encrypted']: self.encrypted_fonts.append(href) else: + if len(data) == len(PLACEHOLDER_GIF) and data == PLACEHOLDER_GIF: + continue imgtype = what(None, data) if imgtype is None: from calibre.utils.magick.draw import identify_data diff --git a/src/calibre/ebooks/mobi/writer2/resources.py b/src/calibre/ebooks/mobi/writer2/resources.py index c364e9aa58..fa5b88e7ca 100644 --- a/src/calibre/ebooks/mobi/writer2/resources.py +++ b/src/calibre/ebooks/mobi/writer2/resources.py @@ -14,7 +14,7 @@ from calibre.ebooks import generate_masthead from calibre.ebooks.oeb.base import OEB_RASTER_IMAGES from calibre.utils.imghdr import what -PLACEHOLDER_GIF = b'GIF89a\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\xff\xff\xff!\xf9\x04\x01\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00@\x02\x01D\x00;' +PLACEHOLDER_GIF = b'GIF89a\x01\x00\x01\x00\xf0\x00\x00\x00\x00\x00\xff\xff\xff!\xf9\x04\x01\x00\x00\x00\x00!\xfe calibre-placeholder-gif-for-azw3\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x02D\x01\x00;' # noqa class Resources(object):