Dont put the code to convert webp in the base module

This commit is contained in:
Kovid Goyal 2021-04-02 16:32:29 +05:30
parent 2d68fbabb0
commit 555b629e17
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C
2 changed files with 9 additions and 9 deletions

View File

@ -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()

View File

@ -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()