I have a custom recipe to download all my favorite comic strips. Similar to the xkcd.recipe.
The one thing I found annoying was the image in the epub were too wide and were getting cut off. So I rotated them. Now long 3 and 4 panel strips are landscape.
here is the code snippet that I used to rotate the images. Hopefully others will find it useful.
Code:
import calibre.utils.PythonMagickWand as pw
Code:
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']
print 'resizing image' + iurl
with pw.ImageMagick():
img = pw.NewMagickWand()
p = pw.NewPixelWand()
if img < 0:
raise RuntimeError('Out of memory')
if not pw.MagickReadImage(img, iurl):
severity = pw.ExceptionType(0)
msg = pw.MagickGetException(img, byref(severity))
raise IOError('Failed to read image from: %s: %s'
%(iurl, msg))
width = pw.MagickGetImageWidth(img)
height = pw.MagickGetImageHeight(img)
if( width > height ) :
print 'Rotate image'
pw.MagickRotateImage(img, p, 90)
if not pw.MagickWriteImage(img, iurl):
raise RuntimeError('Failed to save image to %s'%iurl)
pw.DestroyMagickWand(img)
return soup