PhantomJs: Convert a String to an Image/PDF.

To convert a string or HTML to PNG or PDF using phantomjs:

Create a File say texttoimage.js

Add this code:

var page = require(‘webpage’).create();
page.viewportSize = { width: 200, height : 200 };
page.content =  “This Text will be converted to Image”;
window.setTimeout(function () {
}, 1000);

Save and Run the Script from console: phantomjs texttoimage.js

A image named newimage.png will be generated on same directory where your script is saved.

Here is the output:

PhantomJS : Converted Text to Image

Notice: Undefined variable: bk_thumb_size in /home/content/76/12438476/html/mindgeekblog/wp-content/themes/yeahthemes-sparkle/includes/templates/single-ymal.php on line 159