From 555b629e17e951a1c7a311a907af4bd23c1ce7a0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Fri, 2 Apr 2021 16:32:29 +0530 Subject: [PATCH] Dont put the code to convert webp in the base module --- src/calibre/ebooks/mobi/writer2/resources.py | 11 +++++++++-- src/calibre/ebooks/oeb/base.py | 7 ------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/calibre/ebooks/mobi/writer2/resources.py b/src/calibre/ebooks/mobi/writer2/resources.py index 82c34828b7..9647793e4d 100644 --- a/src/calibre/ebooks/mobi/writer2/resources.py +++ b/src/calibre/ebooks/mobi/writer2/resources.py @@ -89,8 +89,7 @@ class Resources(object): if item.media_type not in OEB_RASTER_IMAGES: continue if item.media_type.lower() == 'image/webp': - self.log.info(f'Converting WebP image {item.href} to PNG') - item.convert_webp() + self.convert_webp(item) try: data = self.process_image(item.data) except: @@ -132,6 +131,14 @@ class Resources(object): self.item_map[item.href] = len(self.records) self.has_fonts = True + def convert_webp(self, item): + from calibre.utils.img import image_and_format_from_data, image_to_data + img, fmt = image_and_format_from_data(item.data) + if fmt == 'webp' and not img.isNull(): + self.log.info(f'Converting WebP image {item.href} to PNG') + item.data = image_to_data(img, fmt='PNG') + item.media_type = 'image/png' + def add_extra_images(self): ''' Add any images that were created after the call to add_resources() diff --git a/src/calibre/ebooks/oeb/base.py b/src/calibre/ebooks/oeb/base.py index e5298169bb..fb763d1d6c 100644 --- a/src/calibre/ebooks/oeb/base.py +++ b/src/calibre/ebooks/oeb/base.py @@ -1145,13 +1145,6 @@ class Manifest(object): href = os.path.normpath(href).replace('\\', '/') return href - def convert_webp(self): - from calibre.utils.img import image_and_format_from_data, image_to_data - img, fmt = image_and_format_from_data(self.data) - if fmt == 'webp' and not img.isNull(): - self.data = image_to_data(img, fmt='PNG') - self.media_type = 'image/png' - def __init__(self, oeb): self.oeb = oeb self.items = set()