diff --git a/src/calibre/ebooks/epub/__init__.py b/src/calibre/ebooks/epub/__init__.py index 6007a1e0a6..863f2f8db0 100644 --- a/src/calibre/ebooks/epub/__init__.py +++ b/src/calibre/ebooks/epub/__init__.py @@ -141,6 +141,10 @@ help on using this feature. action='store_true', help=_('Use the cover detected from the source file in preference ' 'to the specified cover.')) + structure('remove_first_image', ['--remove-first-image'], default=False, + help=_('Remove the first image from the input ebook. Useful if ' + 'the first image in the source file is a cover and you ' + 'are specifying an external cover.')) structure('dont_split_on_page_breaks', ['--dont-split-on-page-breaks'], default=False, help=_('Turn off splitting at page breaks. Normally, input files ' 'are automatically split at every page break into ' diff --git a/src/calibre/ebooks/epub/from_html.py b/src/calibre/ebooks/epub/from_html.py index 16275113c5..6341519c61 100644 --- a/src/calibre/ebooks/epub/from_html.py +++ b/src/calibre/ebooks/epub/from_html.py @@ -141,7 +141,7 @@ class HTMLProcessor(Processor, Rationalizer): p = QPixmap() p.load(path) if not p.isNull(): - p.save(path+'_calibre_converted.jpg') + p.save(path + '_calibre_converted.jpg') os.remove(path) for key, val in self.resource_map.items(): if val == rpath: @@ -206,6 +206,13 @@ class HTMLProcessor(Processor, Rationalizer): # self.convert_image(img) Processor.save(self) + def remove_first_image(self): + images = self.root.xpath('//img') + if images: + images[0].getparent().remove(images[0]) + return True + return False + @@ -227,10 +234,13 @@ def parse_content(filelist, opts, tdir): resource_map, stylesheets = {}, {} toc = TOC(base_path=tdir, type='root') stylesheet_map = {} + first_image_removed = False for htmlfile in filelist: logging.getLogger('html2epub').debug('Processing %s...'%htmlfile) hp = HTMLProcessor(htmlfile, opts, os.path.join(tdir, 'content'), resource_map, filelist, stylesheets) + if not first_image_removed and opts.remove_first_image: + first_image_removed = hp.remove_first_image() hp.populate_toc(toc) hp.save() stylesheet_map[os.path.basename(hp.save_path())] = \