I have set up a new Windows machine where I would like to rasterize a bunch of SVG documents to PNG images. I have simplified Ariya Hidayat's rasterize script to this :
var page = require('webpage').create(),
system = require('system'),
fs = require('fs'),
svgPath, output;
if (system.args.length < 3 || system.args.length > 5) {
console.log('Usage: rasterize.js URL output');
phantom.exit(1);
} else {
svgPath = fs.workingDirectory + '/' + system.args[1];
output = system.args[2];
page.viewportSize = { width: 600, height: 120 };
if (!fs.isFile(svgPath)) {
console.log(svgPath+' does not exist');
phantom.exit(1);
}
page.onLoadFinished = function() {
page.render(output);
console.log('thumbnail created');
phantom.exit(0);
};
page.open(svgPath);
}
And here is how I call the script : bin\phantomjs js/headless/rasterize.js "simple.svg" "simple.svg.png" 2>&1
simple.svg
contains this data :
<svg width="110" height="60" id="simple" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<rect x="10" y="10" height="50" width="100" style="stroke:#ff0000; fill: #0000ff"/>
</svg>
Once the script has been executed (without error), simple.svg.png
is rendered like this :
This is really strange, and I'm pretty sure the thumbnail was correctly generated on the previous machine. Why does it just render the SVG's source code ?