Feb 7 2014

PySide Rendering HTML pages as images via QWebKit

I’m currently working on a small python script to create slates for frame sequences. i figure it would be a nice if the tool could make slates with custom data without the use of 3d party software such as nuke (which is common practice) to build and populate the information…
it then occurred to me, that i could create slate templates via html and css. Giving my clients total control over the design of the slate. My tool would then simply run a search and replace on the html file to populate the key fields that are unique to the slate and then render the html page, as an image to be loaded as the first frame of the sequence….
the over all approach is simple, the only tricky part was figuring out how to use the QWebKit module of PySide to load a local html page and then render it as an image.
Here’s a simple snippet of what i came up with…

from PySide import QtCore,QtGui,QtWebKit
import sys

app = QtGui.QApplication(sys.argv)

view = QtWebKit.QWebPage()
loop = QtCore.QEventLoop()
print 'done loading page proceed to rendering'
size = view.mainFrame().contentsSize()

image = QtGui.QImage(size,QtGui.QImage.Format_ARGB32_Premultiplied)

p = QtGui.QPainter(image)



print 'done!'

2 Responses to “PySide Rendering HTML pages as images via QWebKit”

  • Mike Says:

    Hi Carlos,
    You may be interested in Thinkbox’s DRAFT software product. It comes free with Deadline and was designed exactly for what you doing above and lots more. Nobody should use their expensive Nuke licenses up doing basic comp/slate/image/movie export!


    #justsaying :-)


    • Los Says:

      Hey mike,
      I am aware of of draft, in this particular case I wanted to write something lighter that I can integrate into the Mango “version viewer” app which can already create quicktimes and (upload) submit them for review to to shotgun…

      I’m trying to build mango with the least amount of dependencies to commercial software In the hopes of making it easier to integrate in to different pipelines.
      For example if I client has a proprietary render farm manger, or something other than deadline…
      Thank for your input!!!

Leave a Reply