Here is a short code example to resize PNG images within a news recipe:
Code:
from calibre.utils.magick import Image
...
def postprocess_html(self, soup, first):
maxwidth=800
# Shrink large PNG images
for tag in soup.findAll(lambda tag: tag.name.lower()=='img' and tag.has_key('src')):
iurl = tag['src']
if iurl.upper().endswith('PNG'):
img = Image()
img.open(iurl)
width, height = img.size
if( width > maxwidth ):
factor=maxwidth/width
img.size=(int(width/16 * factor)*16, int(height/16 * factor)*16)
img.save(iurl)
return soup