mirror of
git://github.com/kovidgoyal/calibre.git
synced 2026-05-08 13:43:39 +02:00
Fix PIL imports on OS X
This commit is contained in:
parent
029fd0b3ac
commit
5a8f5726bf
4 changed files with 34 additions and 15 deletions
|
|
@ -11,7 +11,12 @@
|
|||
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 @@
|
|||
|
||||
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 @@ def convert(self, oeb_book, output_path, input_plugin, opts, log):
|
|||
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 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 @@ def _images(self, manifest):
|
|||
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 @@ def _info_section(self, metadata):
|
|||
text += 'BODY=index.html\n'
|
||||
|
||||
return text
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -11,7 +11,12 @@
|
|||
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 @@
|
|||
* Fonts
|
||||
'''
|
||||
class RTFMLizer(object):
|
||||
|
||||
|
||||
def __init__(self, ignore_tables=False):
|
||||
self.ignore_tables = ignore_tables
|
||||
|
||||
|
|
@ -120,7 +125,7 @@ def image_to_hexstring(self, data):
|
|||
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 @@ def dump_text(self, elem, stylizer, tag_stack=[]):
|
|||
text += '%s ' % elem.tail
|
||||
else:
|
||||
text += '{\\par \\pard \\hyphpar %s}' % elem.tail
|
||||
|
||||
|
||||
return text
|
||||
|
|
|
|||
Loading…
Reference in a new issue