mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Dont put the code to convert webp in the base module
This commit is contained in:
parent
2d68fbabb0
commit
555b629e17
@ -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()
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user