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 struct
|
||||||
import zlib
|
import zlib
|
||||||
|
|
||||||
import Image
|
try:
|
||||||
|
from PIL import Image
|
||||||
|
Image
|
||||||
|
except ImportError:
|
||||||
|
import Image
|
||||||
|
|
||||||
import cStringIO
|
import cStringIO
|
||||||
|
|
||||||
from calibre.ebooks.pdb.formatwriter import FormatWriter
|
from calibre.ebooks.pdb.formatwriter import FormatWriter
|
||||||
|
@ -6,7 +6,12 @@ __docformat__ = 'restructuredtext en'
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
import Image
|
try:
|
||||||
|
from PIL import Image
|
||||||
|
Image
|
||||||
|
except ImportError:
|
||||||
|
import Image
|
||||||
|
|
||||||
import cStringIO
|
import cStringIO
|
||||||
|
|
||||||
from calibre.customize.conversion import OutputFormatPlugin
|
from calibre.customize.conversion import OutputFormatPlugin
|
||||||
@ -27,24 +32,24 @@ class PMLOutput(OutputFormatPlugin):
|
|||||||
content = pmlmlizer.extract_content(oeb_book, opts)
|
content = pmlmlizer.extract_content(oeb_book, opts)
|
||||||
with open(os.path.join(tdir, 'index.pml'), 'wb') as out:
|
with open(os.path.join(tdir, 'index.pml'), 'wb') as out:
|
||||||
out.write(content.encode('utf-8'))
|
out.write(content.encode('utf-8'))
|
||||||
|
|
||||||
self.write_images(oeb_book.manifest, tdir)
|
self.write_images(oeb_book.manifest, tdir)
|
||||||
|
|
||||||
pmlz = ZipFile(output_path, 'w')
|
pmlz = ZipFile(output_path, 'w')
|
||||||
pmlz.add_dir(tdir)
|
pmlz.add_dir(tdir)
|
||||||
|
|
||||||
def write_images(self, manifest, out_dir):
|
def write_images(self, manifest, out_dir):
|
||||||
for item in manifest:
|
for item in manifest:
|
||||||
if item.media_type in OEB_IMAGES:
|
if item.media_type in OEB_IMAGES:
|
||||||
im = Image.open(cStringIO.StringIO(item.data))
|
im = Image.open(cStringIO.StringIO(item.data))
|
||||||
|
|
||||||
data = cStringIO.StringIO()
|
data = cStringIO.StringIO()
|
||||||
im.save(data, 'PNG')
|
im.save(data, 'PNG')
|
||||||
data = data.getvalue()
|
data = data.getvalue()
|
||||||
|
|
||||||
name = os.path.splitext(os.path.basename(item.href))[0] + '.png'
|
name = os.path.splitext(os.path.basename(item.href))[0] + '.png'
|
||||||
path = os.path.join(out_dir, name)
|
path = os.path.join(out_dir, name)
|
||||||
|
|
||||||
with open(path, 'wb') as out:
|
with open(path, 'wb') as out:
|
||||||
out.write(data)
|
out.write(data)
|
||||||
|
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
import os.path
|
|
||||||
# -*- coding: utf-8 -*-
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
__license__ = 'GPL 3'
|
__license__ = 'GPL 3'
|
||||||
@ -9,7 +8,12 @@ import os
|
|||||||
import struct
|
import struct
|
||||||
import zlib
|
import zlib
|
||||||
|
|
||||||
import Image
|
try:
|
||||||
|
from PIL import Image
|
||||||
|
Image
|
||||||
|
except ImportError:
|
||||||
|
import Image
|
||||||
|
|
||||||
import cStringIO
|
import cStringIO
|
||||||
|
|
||||||
from calibre.ebooks.rb.rbml import RBMLizer
|
from calibre.ebooks.rb.rbml import RBMLizer
|
||||||
@ -121,7 +125,7 @@ class RBWriter(object):
|
|||||||
name = unique_name(name, used_names)
|
name = unique_name(name, used_names)
|
||||||
used_names.append(name)
|
used_names.append(name)
|
||||||
self.name_map[os.path.basename(item.href)] = name
|
self.name_map[os.path.basename(item.href)] = name
|
||||||
|
|
||||||
images.append((name, data))
|
images.append((name, data))
|
||||||
|
|
||||||
return images
|
return images
|
||||||
@ -140,4 +144,4 @@ class RBWriter(object):
|
|||||||
text += 'BODY=index.html\n'
|
text += 'BODY=index.html\n'
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
|
||||||
|
@ -11,7 +11,12 @@ Transform OEB content into RTF markup
|
|||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import Image
|
try:
|
||||||
|
from PIL import Image
|
||||||
|
Image
|
||||||
|
except ImportError:
|
||||||
|
import Image
|
||||||
|
|
||||||
import cStringIO
|
import cStringIO
|
||||||
|
|
||||||
from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace, \
|
from calibre.ebooks.oeb.base import XHTML, XHTML_NS, barename, namespace, \
|
||||||
@ -73,7 +78,7 @@ TODO:
|
|||||||
* Fonts
|
* Fonts
|
||||||
'''
|
'''
|
||||||
class RTFMLizer(object):
|
class RTFMLizer(object):
|
||||||
|
|
||||||
def __init__(self, ignore_tables=False):
|
def __init__(self, ignore_tables=False):
|
||||||
self.ignore_tables = ignore_tables
|
self.ignore_tables = ignore_tables
|
||||||
|
|
||||||
@ -120,7 +125,7 @@ class RTFMLizer(object):
|
|||||||
data = cStringIO.StringIO()
|
data = cStringIO.StringIO()
|
||||||
im.save(data, 'JPEG')
|
im.save(data, 'JPEG')
|
||||||
data = data.getvalue()
|
data = data.getvalue()
|
||||||
|
|
||||||
raw_hex = ''
|
raw_hex = ''
|
||||||
for char in data:
|
for char in data:
|
||||||
raw_hex += hex(ord(char)).replace('0x', '').rjust(2, '0')
|
raw_hex += hex(ord(char)).replace('0x', '').rjust(2, '0')
|
||||||
@ -230,5 +235,5 @@ class RTFMLizer(object):
|
|||||||
text += '%s ' % elem.tail
|
text += '%s ' % elem.tail
|
||||||
else:
|
else:
|
||||||
text += '{\\par \\pard \\hyphpar %s}' % elem.tail
|
text += '{\\par \\pard \\hyphpar %s}' % elem.tail
|
||||||
|
|
||||||
return text
|
return text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user