FB2 Output: Replace PIL with ImageMagick. Don't convert JPG images to JPG because it's unnecessary.

This commit is contained in:
John Schember 2010-12-04 22:37:34 -05:00
parent 596c8b905b
commit f7d9571c4c

View File

@ -8,18 +8,12 @@ __docformat__ = 'restructuredtext en'
Transform OEB content into FB2 markup Transform OEB content into FB2 markup
''' '''
import cStringIO
from base64 import b64encode from base64 import b64encode
from datetime import datetime from datetime import datetime
from mimetypes import types_map
import re import re
import uuid import uuid
try:
from PIL import Image
Image
except ImportError:
import Image
from lxml import etree from lxml import etree
from calibre import prepare_string_for_xml from calibre import prepare_string_for_xml
@ -27,6 +21,7 @@ from calibre.constants import __appname__, __version__
from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace
from calibre.ebooks.oeb.stylizer import Stylizer from calibre.ebooks.oeb.stylizer import Stylizer
from calibre.ebooks.oeb.base import OEB_RASTER_IMAGES from calibre.ebooks.oeb.base import OEB_RASTER_IMAGES
from calibre.utils.magick import Image
class FB2MLizer(object): class FB2MLizer(object):
''' '''
@ -155,11 +150,11 @@ class FB2MLizer(object):
continue continue
if item.media_type in OEB_RASTER_IMAGES: if item.media_type in OEB_RASTER_IMAGES:
try: try:
im = Image.open(cStringIO.StringIO(item.data)).convert('RGB') if not item.media_type == types_map['.jpeg'] or not item.media_type == types_map['.jpg']:
data = cStringIO.StringIO() im = Image()
im.save(data, 'JPEG') im.load(item.data)
data = data.getvalue() im.set_compression_quality(70)
data = im.export('jpg')
raw_data = b64encode(data) raw_data = b64encode(data)
# Don't put the encoded image on a single line. # Don't put the encoded image on a single line.
data = '' data = ''