Resize large images to reduce size of Daily Mail news recipe

This commit is contained in:
Tom Scholl 2011-05-24 14:23:42 +00:00
parent afde9acfdf
commit 0d4c451e6b

View File

@ -1,4 +1,5 @@
from calibre.web.feeds.news import BasicNewsRecipe from calibre.web.feeds.news import BasicNewsRecipe
from calibre.utils.magick import Image, PixelWand
class TheDailyMail(BasicNewsRecipe): class TheDailyMail(BasicNewsRecipe):
title = u'The Daily Mail' title = u'The Daily Mail'
@ -48,3 +49,19 @@ class TheDailyMail(BasicNewsRecipe):
# return main + '?printingPage=true' # return main + '?printingPage=true'
def postprocess_html(self, soup, first):
#process all the images. assumes that the new html has the correct path
for tag in soup.findAll(lambda tag: tag.name.lower()=='img' and tag.has_key('src')):
iurl = tag['src']
img = Image()
img.open(iurl)
width, height = img.size
print 'img is: ', iurl, 'width is: ', width, 'height is: ', height
if img < 0:
raise RuntimeError('Out of memory')
pw = PixelWand()
if (width > 520 or height > 640):
print 'Resizing image to 50%'
img.size = (width / 2, height / 2)
img.save(iurl)
return soup