mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Fix handling of extensionless image files.
This commit is contained in:
parent
aacaabba66
commit
a85a0821b4
@ -805,6 +805,7 @@ class HTMLConverter(object):
|
|||||||
blockStyle=self.current_block.blockStyle)
|
blockStyle=self.current_block.blockStyle)
|
||||||
|
|
||||||
def process_image(self, path, tag_css, width=None, height=None, dropcaps=False):
|
def process_image(self, path, tag_css, width=None, height=None, dropcaps=False):
|
||||||
|
original_path = path
|
||||||
if self.rotated_images.has_key(path):
|
if self.rotated_images.has_key(path):
|
||||||
path = self.rotated_images[path].name
|
path = self.rotated_images[path].name
|
||||||
if self.scaled_images.has_key(path):
|
if self.scaled_images.has_key(path):
|
||||||
@ -812,8 +813,13 @@ class HTMLConverter(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
im = PILImage.open(path)
|
im = PILImage.open(path)
|
||||||
|
encoding = im.format
|
||||||
|
if encoding:
|
||||||
|
encoding = encoding.upper()
|
||||||
|
if encoding == 'JPG':
|
||||||
|
encoding = 'JPEG'
|
||||||
except IOError, err:
|
except IOError, err:
|
||||||
self.logger.warning('Unable to process image: %s\n%s', path, err)
|
self.logger.warning('Unable to process image: %s\n%s', original_path, err)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
||||||
@ -868,7 +874,7 @@ class HTMLConverter(object):
|
|||||||
self.rotated_images[path] = pt
|
self.rotated_images[path] = pt
|
||||||
width, height = im.size
|
width, height = im.size
|
||||||
except IOError: # PIL chokes on interlaced PNG files and since auto-rotation is not critical we ignore the error
|
except IOError: # PIL chokes on interlaced PNG files and since auto-rotation is not critical we ignore the error
|
||||||
self.logger.debug('Unable to process interlaced PNG %s', path)
|
self.logger.debug('Unable to process interlaced PNG %s', original_path)
|
||||||
finally:
|
finally:
|
||||||
pt.close()
|
pt.close()
|
||||||
|
|
||||||
@ -893,8 +899,9 @@ class HTMLConverter(object):
|
|||||||
|
|
||||||
if not self.images.has_key(path):
|
if not self.images.has_key(path):
|
||||||
try:
|
try:
|
||||||
self.images[path] = ImageStream(path)
|
self.images[path] = ImageStream(path, encoding=encoding)
|
||||||
except LrsError:
|
except LrsError, err:
|
||||||
|
self.logger.warning('Could not process image: %s\n%s', original_path, err)
|
||||||
return
|
return
|
||||||
|
|
||||||
im = Image(self.images[path], x0=0, y0=0, x1=width, y1=height,\
|
im = Image(self.images[path], x0=0, y0=0, x1=width, y1=height,\
|
||||||
@ -972,8 +979,10 @@ class HTMLConverter(object):
|
|||||||
if tag.has_key('href') and not self.link_exclude.match(tag['href']):
|
if tag.has_key('href') and not self.link_exclude.match(tag['href']):
|
||||||
purl = urlparse(tag['href'])
|
purl = urlparse(tag['href'])
|
||||||
path = unquote(purl[2])
|
path = unquote(purl[2])
|
||||||
if path and os.access(path, os.R_OK) and os.path.splitext(path)[1][1:].lower() in \
|
ext = os.path.splitext(path)[1]
|
||||||
['png', 'jpg', 'bmp', 'jpeg']:
|
if ext: ext = ext[1:].lower()
|
||||||
|
if path and os.access(path, os.R_OK) and ext and \
|
||||||
|
ext in ['png', 'jpg', 'bmp', 'jpeg']:
|
||||||
self.process_image(path, tag_css)
|
self.process_image(path, tag_css)
|
||||||
else:
|
else:
|
||||||
text = self.get_text(tag, limit=1000)
|
text = self.get_text(tag, limit=1000)
|
||||||
@ -1199,7 +1208,7 @@ class HTMLConverter(object):
|
|||||||
blockStyle=self.current_block.blockStyle)
|
blockStyle=self.current_block.blockStyle)
|
||||||
self.current_page.append(target)
|
self.current_page.append(target)
|
||||||
src = self.get_text(tag, limit=1000)
|
src = self.get_text(tag, limit=1000)
|
||||||
if self.chapter_detection and tagname.startswith('h'):
|
if not self.disable_chapter_detection and tagname.startswith('h'):
|
||||||
if self.chapter_regex.search(src):
|
if self.chapter_regex.search(src):
|
||||||
self.logger.debug('Detected chapter %s', src)
|
self.logger.debug('Detected chapter %s', src)
|
||||||
self.end_page()
|
self.end_page()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user