mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-06-23 15:30:45 -04:00
Don't die on interlaced PNG
This commit is contained in:
parent
f96adf13a6
commit
2467d2b64c
@ -13,7 +13,7 @@
|
|||||||
## with this program; if not, write to the Free Software Foundation, Inc.,
|
## with this program; if not, write to the Free Software Foundation, Inc.,
|
||||||
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||||
''' E-book management software'''
|
''' E-book management software'''
|
||||||
__version__ = "0.3.67"
|
__version__ = "0.3.68"
|
||||||
__docformat__ = "epytext"
|
__docformat__ = "epytext"
|
||||||
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
__author__ = "Kovid Goyal <kovid@kovidgoyal.net>"
|
||||||
__appname__ = 'libprs500'
|
__appname__ = 'libprs500'
|
||||||
|
@ -789,10 +789,14 @@ class HTMLConverter(object):
|
|||||||
|
|
||||||
def scale_image(width, height):
|
def scale_image(width, height):
|
||||||
pt = PersistentTemporaryFile(suffix='.jpeg')
|
pt = PersistentTemporaryFile(suffix='.jpeg')
|
||||||
|
try:
|
||||||
im.resize((int(width), int(height)), PILImage.ANTIALIAS).convert('RGB').save(pt, 'JPEG')
|
im.resize((int(width), int(height)), PILImage.ANTIALIAS).convert('RGB').save(pt, 'JPEG')
|
||||||
pt.close()
|
pt.close()
|
||||||
self.scaled_images[path] = pt
|
self.scaled_images[path] = pt
|
||||||
return pt.name
|
return pt.name
|
||||||
|
except IOError: # PIL chokes on interlaced PNG images
|
||||||
|
print >>sys.stderr, 'Unable to process interlaced PNG', path
|
||||||
|
return
|
||||||
|
|
||||||
pheight = int(self.current_page.pageStyle.attrs['textheight'])
|
pheight = int(self.current_page.pageStyle.attrs['textheight'])
|
||||||
pwidth = int(self.current_page.pageStyle.attrs['textwidth'])
|
pwidth = int(self.current_page.pageStyle.attrs['textwidth'])
|
||||||
@ -822,13 +826,18 @@ class HTMLConverter(object):
|
|||||||
|
|
||||||
if not self.disable_autorotation and width > pwidth and width > height:
|
if not self.disable_autorotation and width > pwidth and width > height:
|
||||||
pt = PersistentTemporaryFile(suffix='.jpeg')
|
pt = PersistentTemporaryFile(suffix='.jpeg')
|
||||||
|
try:
|
||||||
im = im.rotate(90)
|
im = im.rotate(90)
|
||||||
im.convert('RGB').save(pt, 'JPEG')
|
im.convert('RGB').save(pt, 'JPEG')
|
||||||
path = pt.name
|
path = pt.name
|
||||||
pt.close()
|
|
||||||
self.rotated_images[path] = pt
|
self.rotated_images[path] = pt
|
||||||
width, height = im.size
|
width, height = im.size
|
||||||
|
except IOError, err: # PIL chokes on interlaced PNG files and since auto-rotation is not critical we ignore the error
|
||||||
|
if self.verbose:
|
||||||
|
print >>sys.stderr, 'Unable to autorotate interlaced PNG', path
|
||||||
|
print >>sys.stderr, err
|
||||||
|
finally:
|
||||||
|
pt.close()
|
||||||
|
|
||||||
if height > pheight:
|
if height > pheight:
|
||||||
corrf = pheight/(1.*height)
|
corrf = pheight/(1.*height)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user