Phantomjs creating black output from SVG using page.render

Posted by Neil Young on Stack Overflow See other posts from Stack Overflow or by Neil Young
Published on 2014-06-06T09:23:13Z Indexed on 2014/06/06 9:24 UTC
Read the original article Hit count: 353

Filed under:
|

I have been running PhantomJS 1.9.6 happily on a turnkey Linux server for about 4 months now. Its purpose is to take an SVG file and create different sizes using the page.render function.

This has been doing this but since a few days ago has started to generate a black mono output.

Please see below:

enter image description here

enter image description here

The code:

var page = require('webpage').create(), system = require('system'), address, output, ext, width, height;
if ( system.args.length !== 4 ) {
    console.log("{ \"result\": false, \"message\": \"phantomjs.rasterize: error need address, output, extension arguments\" }");
    //console.log('phantomjs.rasterize: error need address, output, extension arguments');
    phantom.exit(1);
}
else if( system.args[3] !== "jpg" && system.args[3] !== "png"){
console.log("{ \"result\": false, \"message\": \"phantomjs.rasterize: error \"jpg\" or \"png\" only please\" }");
    //console.log('phantomjs.rasterize: error "jpg" or "png" only please');
    phantom.exit(1);
}
else {
address = system.args[1];
output = system.args[2];
ext = system.args[3];
width = 1044;
height = 738;

page.viewportSize = { width: width, height: height }; //postcard size

page.open(address, function (status) {

    if (status !== 'success') {
        console.log("{ \"result\": false, \"message\": \"phantomjs.rasterize: error loading address ["+address+"]\" }");
        //console.log('phantomjs.rasterize: error loading address ['+address+'] ');
        phantom.exit();
    } else {

        window.setTimeout(function () {
            //--> redner full size postcard
            page.render( output + "." + ext );

            //--> redner smaller postcard
            page.zoomFactor = 0.5;
            page.clipRect = {top:0, left:0, width:width*0.5, height:height*0.5};
            page.render( output + ".50." + ext);

            //--> redner postcard thumb
            page.zoomFactor = 0.25;
            page.clipRect = {top:0, left:0, width:width*0.25, height:height*0.25};
            page.render( output + ".25." + ext);

            //--> exit
            console.log("{ \"result\": true, \"message\": \"phantomjs.rasterize: success ["+address+"]>>["+output+"."+ext+"]\" }");
            //console.log('phantomjs.rasterize: success ['+address+']>>['+output+'.'+ext+']');
            phantom.exit();
        }, 100);
    }

});
}

Does anyone know what can be causing this? There have been no server configuration changes that I know of.

Many thanks for your help.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about phantomjs