mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix PIL imports on OS X
This commit is contained in:
parent
029fd0b3ac
commit
5a8f5726bf
@ -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
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user