I'm using phantomjs for taking screenshots of several webpages. To get a screenshot image i have used the following code.
var page = require('webpage').create();
page.viewportSize = { width: 1200,height: 800};
page.open('http://<randomwebpageAddress>', function(status) {
console.log(status);
console.log(page.render('screenshot.png'));
phantom.exit();
});
but the result for some page is
status = "success"
but page.render returns false
my question is:
when does page.render()
return false?
Although the documentation says that there is no return type for render(), it always returns a boolean denoting the success of the rendering operation.
The function will always return false
if the content is empty, which should never happen.
Since the render()
function is capable of rendering into multiple formats such as PNG, JPG, GIF, PDF, the return value may have slightly different meanings.
false
can only be returned, if the format options where set incorrectly.
GIF (pre v2)
It only returns false
when the destination file is not writable.
JPG, PNG (and GIF)
The return value comes from QImage::save()
and denotes a successful rendering and file write.