Remove IM from the book editor

This commit is contained in:
Kovid Goyal 2016-05-04 22:55:57 +05:30
parent af51493118
commit f1af9c9f6d
3 changed files with 11 additions and 10 deletions

View File

@ -6,8 +6,10 @@ from __future__ import (unicode_literals, division, absolute_import,
__license__ = 'GPL v3' __license__ = 'GPL v3'
__copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>' __copyright__ = '2013, Kovid Goyal <kovid at kovidgoyal.net>'
from io import BytesIO
from PIL import Image
from calibre import as_unicode from calibre import as_unicode
from calibre.utils.magick import Image
from calibre.ebooks.oeb.polish.check.base import BaseError, WARN from calibre.ebooks.oeb.polish.check.base import BaseError, WARN
from calibre.ebooks.oeb.polish.check.parsing import EmptyFile from calibre.ebooks.oeb.polish.check.parsing import EmptyFile
@ -51,14 +53,12 @@ def check_raster_images(name, mt, raw):
if not raw: if not raw:
return [EmptyFile(name)] return [EmptyFile(name)]
errors = [] errors = []
i = Image()
try: try:
i.load(raw) i = Image.open(BytesIO(raw))
except Exception as e: except Exception as e:
errors.append(InvalidImage(as_unicode(e.message), name)) errors.append(InvalidImage(as_unicode(e.message), name))
else: else:
if i.colorspace == 'CMYKColorspace': if i.mode == 'CMYK':
errors.append(CMYKImage(_('Image is in the CMYK colorspace'), name)) errors.append(CMYKImage(_('Image is in the CMYK colorspace'), name))
return errors return errors

View File

@ -11,7 +11,7 @@ import shutil, re, os
from calibre.ebooks.oeb.base import OPF, OEB_DOCS, XPath, XLINK, xml2text from calibre.ebooks.oeb.base import OPF, OEB_DOCS, XPath, XLINK, xml2text
from calibre.ebooks.oeb.polish.replace import replace_links, get_recommended_folders from calibre.ebooks.oeb.polish.replace import replace_links, get_recommended_folders
from calibre.utils.magick.draw import identify, identify_data from calibre.utils.imghdr import identify
def set_azw3_cover(container, cover_path, report, options=None): def set_azw3_cover(container, cover_path, report, options=None):
existing_image = options is not None and options.get('existing_image', False) existing_image = options is not None and options.get('existing_image', False)
@ -299,9 +299,10 @@ def create_epub_cover(container, cover_path, existing_image, options=None):
width, height = 600, 800 width, height = 600, 800
try: try:
if existing_image: if existing_image:
width, height = identify_data(container.raw_data(existing_image, decode=False))[:2] width, height = identify(container.raw_data(existing_image, decode=False))[1:]
else: else:
width, height = identify(cover_path)[:2] with lopen(cover_path, 'rb') as csrc:
width, height = identify(csrc)[1:]
except: except:
container.log.exception("Failed to get width and height of cover") container.log.exception("Failed to get width and height of cover")
ar = 'xMidYMid meet' if keep_aspect else 'none' ar = 'xMidYMid meet' if keep_aspect else 'none'

View File

@ -15,7 +15,7 @@ from calibre.ebooks.oeb.base import XPath, xml2text
from calibre.ebooks.oeb.polish.container import OEB_DOCS, OEB_STYLES, OEB_FONTS from calibre.ebooks.oeb.polish.container import OEB_DOCS, OEB_STYLES, OEB_FONTS
from calibre.ebooks.oeb.polish.spell import get_all_words from calibre.ebooks.oeb.polish.spell import get_all_words
from calibre.utils.icu import numeric_sort_key, ord_string, safe_chr from calibre.utils.icu import numeric_sort_key, ord_string, safe_chr
from calibre.utils.magick.draw import identify from calibre.utils.imghdr import identify
from css_selectors import Select, SelectorError from css_selectors import Select, SelectorError
File = namedtuple('File', 'name dir basename size category') File = namedtuple('File', 'name dir basename size category')
@ -50,7 +50,7 @@ def safe_img_data(container, name, mt):
if 'svg' in mt: if 'svg' in mt:
return 0, 0 return 0, 0
try: try:
width, height, fmt = identify(container.name_to_abspath(name)) fmt, width, height = identify(container.name_to_abspath(name))
except Exception: except Exception:
width = height = 0 width = height = 0
return width, height return width, height