From f1af9c9f6d7e6531022b4f2ccc63b19da004d303 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 4 May 2016 22:55:57 +0530 Subject: [PATCH] Remove IM from the book editor --- src/calibre/ebooks/oeb/polish/check/images.py | 10 +++++----- src/calibre/ebooks/oeb/polish/cover.py | 7 ++++--- src/calibre/ebooks/oeb/polish/report.py | 4 ++-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/calibre/ebooks/oeb/polish/check/images.py b/src/calibre/ebooks/oeb/polish/check/images.py index e27f3cbfc0..9cb2ac9ee2 100644 --- a/src/calibre/ebooks/oeb/polish/check/images.py +++ b/src/calibre/ebooks/oeb/polish/check/images.py @@ -6,8 +6,10 @@ from __future__ import (unicode_literals, division, absolute_import, __license__ = 'GPL v3' __copyright__ = '2013, Kovid Goyal ' +from io import BytesIO +from PIL import Image + 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.parsing import EmptyFile @@ -51,14 +53,12 @@ def check_raster_images(name, mt, raw): if not raw: return [EmptyFile(name)] errors = [] - i = Image() try: - i.load(raw) + i = Image.open(BytesIO(raw)) except Exception as e: errors.append(InvalidImage(as_unicode(e.message), name)) else: - if i.colorspace == 'CMYKColorspace': + if i.mode == 'CMYK': errors.append(CMYKImage(_('Image is in the CMYK colorspace'), name)) return errors - diff --git a/src/calibre/ebooks/oeb/polish/cover.py b/src/calibre/ebooks/oeb/polish/cover.py index 6049df26dd..16a3b06d2e 100644 --- a/src/calibre/ebooks/oeb/polish/cover.py +++ b/src/calibre/ebooks/oeb/polish/cover.py @@ -11,7 +11,7 @@ import shutil, re, os 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.utils.magick.draw import identify, identify_data +from calibre.utils.imghdr import identify def set_azw3_cover(container, cover_path, report, options=None): 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 try: 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: - width, height = identify(cover_path)[:2] + with lopen(cover_path, 'rb') as csrc: + width, height = identify(csrc)[1:] except: container.log.exception("Failed to get width and height of cover") ar = 'xMidYMid meet' if keep_aspect else 'none' diff --git a/src/calibre/ebooks/oeb/polish/report.py b/src/calibre/ebooks/oeb/polish/report.py index db39292ff1..26d907dd37 100644 --- a/src/calibre/ebooks/oeb/polish/report.py +++ b/src/calibre/ebooks/oeb/polish/report.py @@ -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.spell import get_all_words 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 File = namedtuple('File', 'name dir basename size category') @@ -50,7 +50,7 @@ def safe_img_data(container, name, mt): if 'svg' in mt: return 0, 0 try: - width, height, fmt = identify(container.name_to_abspath(name)) + fmt, width, height = identify(container.name_to_abspath(name)) except Exception: width = height = 0 return width, height