How to save webkit page image resources from memory?

依然范特西╮ 提交于 2019-12-21 21:33:00

问题


I open page with python, gtk, and webkit. Now - how to save image from that page without downloading it again from the internet?


回答1:


Here is a python program that will save a rendered web page to an image: http://pastie.org/4572412

This should be the section of primary interest to you:

    size = self.browser.mainFrame().contentsSize()
    if width > 0:
        size.setWidth(width)
    self.browser.setViewportSize(size)

    # Render the virtual browsers viewport to an image.
    image = QImage(self.browser.viewportSize(), QImage.Format_ARGB32)
    paint = QPainter(image) #Have the painters target be our image object
    self.browser.mainFrame().render(paint) #Render browser window to painter
    paint.end()
    image = image.scaledToWidth(width) #ensure the image is your desired width
    extension = os.path.splitext(filename)[1][1:].upper()  #save the file as your desired image extension
    if extension not in self.image_extensions:
        raise ValueError("'filename' must be a valid extension: {0}".format(self.image_extensions))
    image.save(filename, extension)

Hope this helps!



来源:https://stackoverflow.com/questions/12080662/how-to-save-webkit-page-image-resources-from-memory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!