diff --git a/src/calibre/ebooks/pdb/ereader/writer.py b/src/calibre/ebooks/pdb/ereader/writer.py index 79cb11fdb9..dc32246957 100644 --- a/src/calibre/ebooks/pdb/ereader/writer.py +++ b/src/calibre/ebooks/pdb/ereader/writer.py @@ -11,7 +11,12 @@ __docformat__ = 'restructuredtext en' import struct import zlib -import Image +try: + from PIL import Image + Image +except ImportError: + import Image + import cStringIO from calibre.ebooks.pdb.formatwriter import FormatWriter diff --git a/src/calibre/ebooks/pml/output.py b/src/calibre/ebooks/pml/output.py index 8be8cc18ee..700407d058 100644 --- a/src/calibre/ebooks/pml/output.py +++ b/src/calibre/ebooks/pml/output.py @@ -6,7 +6,12 @@ __docformat__ = 'restructuredtext en' import os -import Image +try: + from PIL import Image + Image +except ImportError: + import Image + import cStringIO from calibre.customize.conversion import OutputFormatPlugin @@ -27,24 +32,24 @@ class PMLOutput(OutputFormatPlugin): content = pmlmlizer.extract_content(oeb_book, opts) with open(os.path.join(tdir, 'index.pml'), 'wb') as out: out.write(content.encode('utf-8')) - + self.write_images(oeb_book.manifest, tdir) pmlz = ZipFile(output_path, 'w') pmlz.add_dir(tdir) - + def write_images(self, manifest, out_dir): for item in manifest: if item.media_type in OEB_IMAGES: im = Image.open(cStringIO.StringIO(item.data)) - + data = cStringIO.StringIO() im.save(data, 'PNG') data = data.getvalue() - + name = os.path.splitext(os.path.basename(item.href))[0] + '.png' path = os.path.join(out_dir, name) - + with open(path, 'wb') as out: out.write(data) diff --git a/src/calibre/ebooks/rb/writer.py b/src/calibre/ebooks/rb/writer.py index f9057d5c61..4e697f6d36 100644 --- a/src/calibre/ebooks/rb/writer.py +++ b/src/calibre/ebooks/rb/writer.py @@ -1,4 +1,3 @@ -import os.path # -*- coding: utf-8 -*- __license__ = 'GPL 3' @@ -9,7 +8,12 @@ import os import struct import zlib -import Image +try: + from PIL import Image + Image +except ImportError: + import Image + import cStringIO from calibre.ebooks.rb.rbml import RBMLizer @@ -121,7 +125,7 @@ class RBWriter(object): name = unique_name(name, used_names) used_names.append(name) self.name_map[os.path.basename(item.href)] = name - + images.append((name, data)) return images @@ -140,4 +144,4 @@ class RBWriter(object): text += 'BODY=index.html\n' return text - \ No newline at end of file + diff --git a/src/calibre/ebooks/rtf/rtfml.py b/src/calibre/ebooks/rtf/rtfml.py index cb8e9af883..dbecd62faf 100644 --- a/src/calibre/ebooks/rtf/rtfml.py +++ b/src/calibre/ebooks/rtf/rtfml.py @@ -11,7 +11,12 @@ Transform OEB content into RTF markup import os import re -import Image +try: + from PIL import Image + Image +except ImportError: + import Image + import cStringIO from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace, \ @@ -73,7 +78,7 @@ TODO: * Fonts ''' class RTFMLizer(object): - + def __init__(self, ignore_tables=False): self.ignore_tables = ignore_tables @@ -120,7 +125,7 @@ class RTFMLizer(object): data = cStringIO.StringIO() im.save(data, 'JPEG') data = data.getvalue() - + raw_hex = '' for char in data: raw_hex += hex(ord(char)).replace('0x', '').rjust(2, '0') @@ -230,5 +235,5 @@ class RTFMLizer(object): text += '%s ' % elem.tail else: text += '{\\par \\pard \\hyphpar %s}' % elem.tail - + return text