mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Remove IM from some more places
This commit is contained in:
parent
2d7ab2bd05
commit
5593a1af48
@ -40,17 +40,16 @@ def encode_thumbnail(thumbnail):
|
|||||||
'''
|
'''
|
||||||
Encode the image part of a thumbnail, then return the 3 part tuple
|
Encode the image part of a thumbnail, then return the 3 part tuple
|
||||||
'''
|
'''
|
||||||
from calibre.utils.magick import Image
|
from calibre.utils.imghdr import identify
|
||||||
|
|
||||||
if thumbnail is None:
|
if thumbnail is None:
|
||||||
return None
|
return None
|
||||||
if not isinstance(thumbnail, (tuple, list)):
|
if not isinstance(thumbnail, (tuple, list)):
|
||||||
try:
|
try:
|
||||||
img = Image()
|
width, height = identify(bytes(thumbnail))[1:]
|
||||||
img.load(thumbnail)
|
if width < 0 or height < 0:
|
||||||
width, height = img.size
|
return None
|
||||||
thumbnail = (width, height, thumbnail)
|
thumbnail = (width, height, thumbnail)
|
||||||
except:
|
except Exception:
|
||||||
return None
|
return None
|
||||||
return (thumbnail[0], thumbnail[1], b64encode(str(thumbnail[2])))
|
return (thumbnail[0], thumbnail[1], b64encode(str(thumbnail[2])))
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ from calibre.utils.cleantext import clean_xml_chars
|
|||||||
from calibre.utils.config_base import tweaks
|
from calibre.utils.config_base import tweaks
|
||||||
from calibre.utils.date import parse_only_date
|
from calibre.utils.date import parse_only_date
|
||||||
from calibre.utils.localization import canonicalize_lang
|
from calibre.utils.localization import canonicalize_lang
|
||||||
from calibre.utils.magick.draw import identify_data
|
from calibre.utils.imghdr import identify
|
||||||
|
|
||||||
class InvalidKFX(ValueError):
|
class InvalidKFX(ValueError):
|
||||||
pass
|
pass
|
||||||
@ -313,10 +313,10 @@ def read_metadata_kfx(stream, read_cover=True):
|
|||||||
if read_cover and m[COVER_KEY]:
|
if read_cover and m[COVER_KEY]:
|
||||||
try:
|
try:
|
||||||
data = base64.standard_b64decode(m[COVER_KEY])
|
data = base64.standard_b64decode(m[COVER_KEY])
|
||||||
w, h, fmt = identify_data(data)
|
fmt, w, h = identify(bytes(data))
|
||||||
except Exception:
|
except Exception:
|
||||||
w, h, fmt = 0, 0, None
|
w, h, fmt = 0, 0, None
|
||||||
if fmt and w and h:
|
if fmt and w > -1 and h > -1:
|
||||||
mi.cover_data = (fmt, data)
|
mi.cover_data = (fmt, data)
|
||||||
|
|
||||||
return mi
|
return mi
|
||||||
|
@ -10,7 +10,7 @@ from urllib import unquote
|
|||||||
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from calibre import guess_type
|
from calibre import guess_type
|
||||||
from calibre.utils.magick.draw import identify_data
|
from calibre.utils.imghdr import identify
|
||||||
|
|
||||||
class CoverManager(object):
|
class CoverManager(object):
|
||||||
|
|
||||||
@ -115,10 +115,10 @@ class CoverManager(object):
|
|||||||
if x.href == urlnormalize(href):
|
if x.href == urlnormalize(href):
|
||||||
try:
|
try:
|
||||||
raw = x.data
|
raw = x.data
|
||||||
return identify_data(raw)[:2]
|
return identify(raw)[1:]
|
||||||
except:
|
except Exception:
|
||||||
self.log.exception('Failed to read image dimensions')
|
self.log.exception('Failed to read cover image dimensions')
|
||||||
return None, None
|
return -1, -1
|
||||||
|
|
||||||
def insert_cover(self):
|
def insert_cover(self):
|
||||||
from calibre.ebooks.oeb.base import urldefrag
|
from calibre.ebooks.oeb.base import urldefrag
|
||||||
@ -132,7 +132,7 @@ class CoverManager(object):
|
|||||||
if href is None:
|
if href is None:
|
||||||
return
|
return
|
||||||
width, height = self.inspect_cover(href)
|
width, height = self.inspect_cover(href)
|
||||||
if width is None or height is None:
|
if width == -1 or height == -1:
|
||||||
self.log.warning('Failed to read cover dimensions')
|
self.log.warning('Failed to read cover dimensions')
|
||||||
width, height = 600, 800
|
width, height = 600, 800
|
||||||
# if self.preserve_aspect_ratio:
|
# if self.preserve_aspect_ratio:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user