mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Remove IM from Plucker input
This commit is contained in:
parent
768b8ba990
commit
26c399100d
@ -14,9 +14,9 @@ from collections import OrderedDict
|
||||
|
||||
from calibre import CurrentDir
|
||||
from calibre.ebooks.pdb.formatreader import FormatReader
|
||||
from calibre.ptempfile import TemporaryFile
|
||||
from calibre.utils.magick import Image, create_canvas
|
||||
from calibre.ebooks.compression.palmdoc import decompress_doc
|
||||
from calibre.utils.imghdr import identify
|
||||
from calibre.utils.img import save_cover_data_to, Canvas, image_from_data
|
||||
|
||||
DATATYPE_PHTML = 0
|
||||
DATATYPE_PHTML_COMPRESSED = 1
|
||||
@ -376,7 +376,7 @@ class Reader(FormatReader):
|
||||
|
||||
# Images.
|
||||
# Cache the image sizes in case they are used by a composite image.
|
||||
image_sizes = {}
|
||||
images = set()
|
||||
if not os.path.exists(os.path.join(output_dir, 'images/')):
|
||||
os.makedirs(os.path.join(output_dir, 'images/'))
|
||||
with CurrentDir(os.path.join(output_dir, 'images/')):
|
||||
@ -393,14 +393,8 @@ class Reader(FormatReader):
|
||||
elif self.header_record.compression == 2:
|
||||
idata = zlib.decompress(section_data)
|
||||
try:
|
||||
with TemporaryFile(suffix='.palm') as itn:
|
||||
with open(itn, 'wb') as itf:
|
||||
itf.write(idata)
|
||||
im = Image()
|
||||
im.read(itn)
|
||||
image_sizes[uid] = im.size
|
||||
im.set_compression_quality(70)
|
||||
im.save('%s.jpg' % uid)
|
||||
save_cover_data_to(idata, '%s.jpg' % uid, compression_quality=70)
|
||||
images.add(uid)
|
||||
self.log.debug('Wrote image with uid %s to images/%s.jpg' % (uid, uid))
|
||||
except Exception as e:
|
||||
self.log.error('Failed to write image with uid %s: %s' % (uid, e))
|
||||
@ -418,11 +412,9 @@ class Reader(FormatReader):
|
||||
row_width = 0
|
||||
col_height = 0
|
||||
for col in row:
|
||||
if col not in image_sizes:
|
||||
if col not in images:
|
||||
raise Exception('Image with uid: %s missing.' % col)
|
||||
im = Image()
|
||||
im.read('%s.jpg' % col)
|
||||
w, h = im.size
|
||||
w, h = identify(lopen('%s.jpg' % col, 'rb'))[1:]
|
||||
row_width += w
|
||||
if col_height < h:
|
||||
col_height = h
|
||||
@ -431,22 +423,21 @@ class Reader(FormatReader):
|
||||
height += col_height
|
||||
# Create a new image the total size of all image
|
||||
# parts. Put the parts into the new image.
|
||||
canvas = create_canvas(width, height)
|
||||
with Canvas(width, height) as canvas:
|
||||
y_off = 0
|
||||
for row in section_data.layout:
|
||||
x_off = 0
|
||||
largest_height = 0
|
||||
for col in row:
|
||||
im = Image()
|
||||
im.read('%s.jpg' % col)
|
||||
im = image_from_data(lopen('%s.jpg' % col, 'rb').read())
|
||||
canvas.compose(im, x_off, y_off)
|
||||
w, h = im.size
|
||||
w, h = im.width(), im.height()
|
||||
x_off += w
|
||||
if largest_height < h:
|
||||
largest_height = h
|
||||
y_off += largest_height
|
||||
canvas.set_compression_quality(70)
|
||||
canvas.save('%s.jpg' % uid)
|
||||
with lopen('%s.jpg' % uid) as out:
|
||||
out.write(canvas.export(compression_quality=70))
|
||||
self.log.debug('Wrote composite image with uid %s to images/%s.jpg' % (uid, uid))
|
||||
except Exception as e:
|
||||
self.log.error('Failed to write composite image with uid %s: %s' % (uid, e))
|
||||
|
Loading…
x
Reference in New Issue
Block a user