View Single Post
Old 05-05-2016, 05:58 AM   #1
epubli
Enthusiast
epubli began at the beginning.
 
Posts: 25
Karma: 10
Join Date: Nov 2012
Device: Pocketbook Inkpad 3
Rescale images retrieved by GoComics recipe

Hi,

could someone help me with the builtin GoComics recipe. I a trying to download the Agnes comic (http://www.gocomics.com/agnes). I would like to rescale the images to max dimensions of 800x600 preserving the aspect ratio. The downloaded comic images are PNG with about 900x300pixels.

I have unsuccessfully tried to set
Code:
scale_news_images = (800, 600)
This resulted in distorted png images with 800x600 size.


I also tried to modify the images in postprocess_html function, but the image object used by calibre does not seem to have the .thumbnail method explained at stackoverflow (http://stackoverflow.com/questions/2...s-aspect-ratio).

My third try was the following code code for postprocess_html I found in another recipe. This code happens to create only cropped images:

Code:
    
def postprocess_html(self, soup, first):
        maxwidth=800
        maxheight=600
        for tag in soup.findAll(lambda tag: tag.name.lower()=='img' and tag.has_key('src')):
            iurl = tag['src']
            img = Image()
            img.open(iurl)
            left=0
            top=0
            border_color='#ffffff'
            if (width > maxwidth) :
                newheight= float(height) / width * maxwidth
                canvas = create_canvas(maxwidth, newheight,border_color)
            canvas.compose(img, left, top)
            #img = canvas
            #img.save(iurl)
            canvas.save(iurl)
            width, height = canvas.size
            print '***NEW img width is: ', width, 'height is: ', height
        return soup
Another related question. When I test my recipe with "ebook-convert testgocomics.recipe testgocomic --test -vv", it
fetches the comics using several threads which makes reading the debugging output almost impossible. How can I limit to 1 thread ?

Thanks for your help !
epubli is offline   Reply With Quote