I have a PhantomJS app where I'd like to take a series of screenshots from a JS-driven page (via page.renderBase64('PNG')
) and then stitch those screenshots into a GIF.
As far as I can tell, there's no way in Node to build a GIF out of pure base64 strings, and I'd really prefer not to write each frame to the disk and then go outside Node to stitch them together with ImageMagick or the like -- that would dramatically slow down the process. So my plan was to paint the base64 images onto a canvas and then add the canvas to a Node GIF generator.
While I can use node-canvas in a Node environment with no problem, when I include require('canvas')
in my Phantom script, it fails when I initiate a new Canvas object, spitting out the usual errors one sees when missing dependencies:
Error: Cannot find module './lib/node-canvas/build/Release/canvas'
phantomjs://platform/bootstrap.js:299 in require
phantomjs://platform/bootstrap.js:263 in require
Part of the problem, I think, is that Phantom is running Node from a different environment where all the dependencies aren't present. But I don't quite understand how Node and PhantomJS different in their execution of Javascript. I'm not clear what phantomjs://platform/bootstrap.js
is or whether it's something I can extend.
To be clear, I'm using the Phantom-Node bridge where I begin the script with var page = require('webpage').create();
. I then execute the script using phantomjs
from the command line.
TL;DR: Requiring C++-based Node module, node-canvas, from a PhantomJS script it fails, where it doesn't fail when run from Node. How are the environments different? Why do some Node modules work while others don't?
via Chris Wilson
No comments:
Post a Comment