From 0d4c451e6befbf59860efedd224fc85c83420702 Mon Sep 17 00:00:00 2001 From: Tom Scholl Date: Tue, 24 May 2011 14:23:42 +0000 Subject: [PATCH] Resize large images to reduce size of Daily Mail news recipe --- recipes/daily_mail.recipe | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/recipes/daily_mail.recipe b/recipes/daily_mail.recipe index ac2dfd1777..40d43864c7 100644 --- a/recipes/daily_mail.recipe +++ b/recipes/daily_mail.recipe @@ -1,4 +1,5 @@ from calibre.web.feeds.news import BasicNewsRecipe +from calibre.utils.magick import Image, PixelWand class TheDailyMail(BasicNewsRecipe): title = u'The Daily Mail' @@ -46,5 +47,21 @@ class TheDailyMail(BasicNewsRecipe): #def print_version(self, url): # main = url.partition('?')[0] # 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