LRF Output: Resize rather than crop images when the img tag specifies a width and height smaller than the actual image size. Fixes #1793 (Semi-failed conversion HTML to LRF)

This commit is contained in:
Kovid Goyal 2009-02-08 12:07:12 -08:00
parent e133ddda55
commit 526bdc6049

View File

@ -917,7 +917,8 @@ class HTMLConverter(object, LoggingInterface):
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, rescale=False):
def detect_encoding(im): def detect_encoding(im):
fmt = im.format fmt = im.format
if fmt == 'JPG': if fmt == 'JPG':
@ -936,10 +937,6 @@ class HTMLConverter(object, LoggingInterface):
return return
encoding = detect_encoding(im) encoding = detect_encoding(im)
if width == None or height == None:
width, height = im.size
factor = 720./self.profile.dpi
def scale_image(width, height): def scale_image(width, height):
if width <= 0: if width <= 0:
@ -955,8 +952,15 @@ class HTMLConverter(object, LoggingInterface):
return pt.name return pt.name
except (IOError, SystemError), err: # PIL chokes on interlaced PNG images as well a some GIF images except (IOError, SystemError), err: # PIL chokes on interlaced PNG images as well a some GIF images
self.log_warning(_('Unable to process image %s. Error: %s')%(path, err)) self.log_warning(_('Unable to process image %s. Error: %s')%(path, err))
return None
if width == None or height == None:
width, height = im.size
elif rescale and (width < im.size[0] or height < im.size[1]):
path = scale_image(width, height)
if not path:
return
factor = 720./self.profile.dpi
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'])
@ -1518,7 +1522,8 @@ class HTMLConverter(object, LoggingInterface):
except: except:
pass pass
dropcaps = tag.has_key('class') and tag['class'] == 'libprs500_dropcaps' dropcaps = tag.has_key('class') and tag['class'] == 'libprs500_dropcaps'
self.process_image(path, tag_css, width, height, dropcaps=dropcaps) self.process_image(path, tag_css, width, height,
dropcaps=dropcaps, rescale=True)
elif not urlparse(tag['src'])[0]: elif not urlparse(tag['src'])[0]:
self.log_warn('Could not find image: '+tag['src']) self.log_warn('Could not find image: '+tag['src'])
else: else: