View Single Post
Old 01-17-2011, 02:28 PM   #9
Tegan
Connoisseur
Tegan began at the beginning.
 
Posts: 59
Karma: 10
Join Date: Jan 2011
Device: Kindle 1st Gen, Kindle 3 SO
Quote:
Originally Posted by Starson17 View Post
I just rotate my reader from portrait to landscape and the G-sensor redoes the image. The CSS for images in those recipes is set to make the width equal to the max width of the device.
Yeah, I've got a Kindle 1, so rotation of the reader itself doesn't do anything.

I just am trying to learn the code for the recipes by taking apart old code and trying to figure it out, while in the meantime making the recipes work better for me. I understand the bit about rotation, but I still haven't quite worked out what the lambda call does.

My understanding of that code is that it calls the graphic editor (Magick Wand) which Kovid points out has been replaced with a new call. Ok, got that. Then it does the postprocess to rotate the image. I understand the gist of it, but I'm an English grad, not a programmer, so I'm not sure what each bit is doing and searches aren't yielding much help.

Line by line:

Code:
for tag in soup.findAll(lambda tag: tag.name.lower()=='img' and tag.has_key('src')):
This is the bit that confuses me most. Is there a beginners guide to soup? What is the lambda? If someone can help me with that, maybe I can figure it out for myself.

Code:
 with pw.ImageMagick():
                img = pw.NewMagickWand()
                p = pw.NewPixelWand()
Ok, this is calling the image editor? How would that change with the new names? Where does one find the names of the Magick calls?

Code:
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)
                for divtag in soup.findAll('div'):
                   del(divtag['style'])
        return soup
Same here. I see a bunch of different calls to the image editor, but I can't find any documentation on how those calls should be phrased in the recipe. I've been Googling like mad, and still can't figure out some of the basics. I think there is a level of programming that I'm missing.

Can this bit of code be rewritten to apply to the current GoComics and Comics.com recipes so they will be automagically rotated for me? I'd be delighted if so. It would keep me from having to squint at the comics every day.
Tegan is offline   Reply With Quote