mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix #5195 (cbr -> epub runs out of memory when coverting massive files ;-))
This commit is contained in:
parent
7cdf57969c
commit
f25d0f1ef2
@ -1048,6 +1048,22 @@ class Manifest(object):
|
||||
self._data = None
|
||||
return property(fget, fset, fdel, doc=doc)
|
||||
|
||||
def unload_data_from_memory(self):
|
||||
if isinstance(self._data, (str, bytes)):
|
||||
from calibre.ptempfile import PersistentTemporaryFile
|
||||
pt = PersistentTemporaryFile('_oeb_base_mem_unloader')
|
||||
pt.write(self._data)
|
||||
pt.close()
|
||||
def loader(*args):
|
||||
with open(pt.name, 'rb') as f:
|
||||
ans = f.read()
|
||||
os.remove(pt.name)
|
||||
return ans
|
||||
self._loader = loader
|
||||
self._data = None
|
||||
|
||||
|
||||
|
||||
def __str__(self):
|
||||
data = self.data
|
||||
if isinstance(data, etree._Element):
|
||||
|
@ -56,17 +56,21 @@ class RescaleImages(object):
|
||||
scaled, new_width, new_height = fit_image(width, height,
|
||||
page_width, page_height)
|
||||
if scaled:
|
||||
data = None
|
||||
self.log('Rescaling image from %dx%d to %dx%d'%(
|
||||
width, height, new_width, new_height), item.href)
|
||||
if qt:
|
||||
img = img.scaled(new_width, new_height,
|
||||
Qt.IgnoreAspectRatio, Qt.SmoothTransformation)
|
||||
item.data = pixmap_to_data(img)
|
||||
data = pixmap_to_data(img)
|
||||
else:
|
||||
im = im.resize((int(new_width), int(new_height)), PILImage.ANTIALIAS)
|
||||
of = cStringIO.StringIO()
|
||||
im.convert('RGB').save(of, 'JPEG')
|
||||
item.data = of.getvalue()
|
||||
data = of.getvalue()
|
||||
if data is not None:
|
||||
item.data = data
|
||||
item.unload_data_from_memory()
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user