Tom Gullen
Tom Gullen

Reputation: 61773

Javascript copy canvas state as image

Seen a good charts plugin I want to use:

http://www.jqplot.com/tests/stackedTests.php

But for my visitors, they may want to save this as an image (via right click, copy as image menu item) or alternatively a button that says save as image or something similar.

So is it possible to save the canvas in any given state as an image file?

Upvotes: 0

Views: 1895

Answers (2)

João Neves
João Neves

Reputation: 957

If you are willing to use a pre-made library, you can try using Canvas2Image.

Otherwise there are a few Canvas methods that Canvas2Image wraps around and explain in more detail in the above site, namely the toDataURL method in the Canvas object that returns the data base64 encoded in the image format that you require. It's not 100% cross-browser, I think, but it's the "right" way of getting it.

Upvotes: 1

stecb
stecb

Reputation: 14766

I think toDataURL could help you :)

Upvotes: 4

Related Questions