Save canvas toDataURL() data to file

590 views
Skip to first unread message

Dan Aharon-Shalom

unread,
Mar 24, 2012, 9:27:09 AM3/24/12
to phantomjs
Hey,
I been trying to use PhantomJS to get the image data from a canvas
element by using the evaluate() function to get the canvas data:
var data = page.evaluate(function() { return $
('canvas').toDataURL() });
In all the browser I get about 16k string length but in Phantom it
gets 3M string length...

is there some way I can use some how fix this? any ideas?

Thank you,
Dan

Alessandro Portale

unread,
Mar 24, 2012, 12:47:22 PM3/24/12
to phan...@googlegroups.com, phantomjs
Thank you for the report.

Is the data encoded differently between browser and PhntomJS? And is the PhantomJS one actually valid image data?

A small example or the data strings from browser and PhantomJS would be helpful when trying to fix it. Ideally, as a bug report: http://code.google.com/p/phantomjs/issues

Dan Aharon-Shalom

unread,
Mar 24, 2012, 1:15:00 PM3/24/12
to phantomjs
Thank you for the reply, I opend a new issue
http://code.google.com/p/phantomjs/issues/detail?id=455&thanks=455&ts=1332609044
I explained as much as I could and attached the relevant samples and
code files.

For You Question, the PhantomJS does not produce a valid image data.

I'll be glad to find a solution for this issue, I been trying all day
to find a way to export the canvas data...

Dan

On Mar 24, 6:47 pm, Alessandro Portale

Luis V.S.

unread,
Jun 3, 2013, 12:52:09 PM6/3/13
to phan...@googlegroups.com
Any progress on this issue? I'm facing the same problem; a PNG rendered using render64 is 25kb and using canvas.toDataURL is 630-650kb, it seems that toDataURL implementation is not encoding the PNG image.

I can use the render64 method but being able to use toDataURL would make my codebase cleaner.

Kind regards,

Luis
Reply all
Reply to author
Forward
0 new messages