Remove IM from some more places

This commit is contained in:
Kovid Goyal 2016-05-05 07:30:18 +05:30
parent 2d7ab2bd05
commit 5593a1af48
3 changed files with 14 additions and 15 deletions

View File

@ -40,17 +40,16 @@ def encode_thumbnail(thumbnail):
'''
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:
return None
if not isinstance(thumbnail, (tuple, list)):
try:
img = Image()
img.load(thumbnail)
width, height = img.size
width, height = identify(bytes(thumbnail))[1:]
if width < 0 or height < 0:
return None
thumbnail = (width, height, thumbnail)
except:
except Exception:
return None
return (thumbnail[0], thumbnail[1], b64encode(str(thumbnail[2])))

View File

@ -17,7 +17,7 @@ from calibre.utils.cleantext import clean_xml_chars
from calibre.utils.config_base import tweaks
from calibre.utils.date import parse_only_date
from calibre.utils.localization import canonicalize_lang
from calibre.utils.magick.draw import identify_data
from calibre.utils.imghdr import identify
class InvalidKFX(ValueError):
pass
@ -313,10 +313,10 @@ def read_metadata_kfx(stream, read_cover=True):
if read_cover and m[COVER_KEY]:
try:
data = base64.standard_b64decode(m[COVER_KEY])
w, h, fmt = identify_data(data)
fmt, w, h = identify(bytes(data))
except Exception:
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)
return mi

View File

@ -10,7 +10,7 @@ from urllib import unquote
from lxml import etree
from calibre import guess_type
from calibre.utils.magick.draw import identify_data
from calibre.utils.imghdr import identify
class CoverManager(object):
@ -115,10 +115,10 @@ class CoverManager(object):
if x.href == urlnormalize(href):
try:
raw = x.data
return identify_data(raw)[:2]
except:
self.log.exception('Failed to read image dimensions')
return None, None
return identify(raw)[1:]
except Exception:
self.log.exception('Failed to read cover image dimensions')
return -1, -1
def insert_cover(self):
from calibre.ebooks.oeb.base import urldefrag
@ -132,7 +132,7 @@ class CoverManager(object):
if href is None:
return
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')
width, height = 600, 800
# if self.preserve_aspect_ratio: