3

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.

UPDATE:

It appears the problem is not with PhantomJS but with an update made to the Google Chrome browser on the 20th May (http://googlechromereleases.blogspot.co.uk/2014/05/stable-channel-update_20.html). This effectively changed the way SVG files are built and obviously a change has been made that stops PhantomJS reading the SVG correctly.

The application we have runs correctly on Safari so as expected my first thought about the code not being the issue was correct.

I have logged a forum post in Google Groups (https://groups.google.com/forum/#!topic/google-chrome-techhelp/Y99OXOtikXI) to try and get some help on this, whether it be to roll back the Chrome browser or to provide a flag that enables me to turn off this breaking feature.

FURTHER UPDATE:

This is an issue with an update made to the Google Chrome browser. I have logged a bug report at the address below so hopefully it can be rectified as soon as possible. Thank you for all your help.

http://code.google.com/p/chromium/issues/detail?id=382536

Neil Young
  • 556
  • 10
  • 23
  • Probably related: http://stackoverflow.com/q/24035275/1816580 – Artjom B. Jun 06 '14 at 13:46
  • Have tried updating to 1.9.7? – Artjom B. Jun 06 '14 at 13:47
  • I updated this from 1.9.6 to 1.9.7 and I still get the same output. Still stumped as to what this might be... – Neil Young Jun 06 '14 at 22:38
  • I still have the same problem here. Tried all your suggestions but still rendering a mono output. I tried running code to convert a test SVG (http://ariya.github.com/svg/tiger.svg). This brings up a black background so I am assuming this is related. Anyone know of a option or filter that can be passed to the page.render function in order to add transparency so the SVG can render as a JPG correctly? – Neil Young Jun 09 '14 at 09:11
  • Just curious: is this only an issue with jpg or are png and pdf also affected? – Artjom B. Jun 09 '14 at 09:18
  • PNG has the same problem but does not display a black background but white. Seems that the files I am trying to bring into the SVG through http (and which appear in the SVG) are not being read at all by PhantomJS as they are not appearing. They do appear however when I browse to the SVG directly through the web address. – Neil Young Jun 09 '14 at 09:40
  • After further investigation it appears that when building the SVG before it was adding the link to an image as a data url for the background images. Seems not to be using these any longer and now using absolute paths. Nothing has changed in the code so struggling to see why this is happening. – Neil Young Jun 09 '14 at 13:01
  • What happens when you pass it a normal HTML URL, such as Google? – Ahmed Nuaman Jun 09 '14 at 15:20
  • Hi Ahmed, it works with a HTML page. I have written an update above. Because we build out the SVG file client side and then pass this onto the server, it turns out Google Chrome made an update that breaks the way PhantomJS reads these new SVG files. – Neil Young Jun 09 '14 at 15:57

0 Answers0