node-chimera
node-chimera copied to clipboard
Enhanced image rendering methods
Added new methods to the native module to allow:
- captureBytes() - alternative to capture - will return a node Buffer with image data rather than saving to file.
- renderSnippet() - render a snippet of HTML rather than a remote URL.
- clipToElement() - clip the rendering to a given element (by css selector). Will work with capture() and captureBytes()
perform() can now also take an option "html" instead of "url" to load the html directly.
A combination of these new methods will allow a streamlined pipeline if you wish to render the contents of a locally held snippet of html and return it directly via a webserver. This will avoid a number of unnecessary file save/loads or converting image data to Base64.
Notes:
- These changes were coded against the qt 4.8 version, and on the whole worked OK. I've been having issues getting qt5 built on Ubuntu 12.04, so I haven't been able to regenerate the .moc file.
- There are a couple of example files that exercise the new methods.
- On reflection, renderSnippet is probably badly named. loadSnippet, loadHtml or setHtml maybe?
- I have been seeing some issues running renderSnippet multiple times in a row. I think this is a node/libuv callback related issue. I'll put a gist up with code demonstrating this.
Gist: https://gist.github.com/dhendo/6020429