Tomas Katz
Tomas Katz

Reputation: 1834

Creating in img file (bmp,jpg,png) from html elements

I have a page that includes a number of canvas elements each with its own shape (rec,line etc...) and also css3 properties (rotate,deg,transform etc...). i need to take that html element or page and render it as an image file including all the child elements and their styling.

is there a solution for this problem??? i must convert it to an img i dont have any other alternative !!!

Upvotes: 0

Views: 1424

Answers (1)

subZero
subZero

Reputation: 5176

You can use PhantomJS for this. Here is an example in node:

var page = require('webpage').create();
page.open('http://example.org/', function() {
    var clipRect = page.evaluate(function () {
        return document.getElementById('myID').getBoundingClientRect();
    });

    page.clipRect = {
        top:    clipRect.top,
        left:   clipRect.left,
        width:  clipRect.width,
        height: clipRect.height
    };

    page.render('myCapture.png');
    phantom.exit();
});

This will go to example.org and take a screenshot of everything inside #myID

Upvotes: 1

Related Questions