From SVG to Canvas and Back (demo)
SVG
circle
png image
svg image
import canvas
clear
Canvas
pixel
png image
svg image
import svg
clear
NO CANVAS FOR YOU
Canvas to SVG
Canvas.toDataURL("image/png");
Works with all major browsers, including IE9.
SVG to Canvas
SVG.toDataURL('image/png');
Emulated with
canvg
.
Works with all major browsers, including IE9.
Canvas becomes write-only only if the imported SVG has images from different origin,
or embedded svg images
.
Server-side conversion with Ajax
Works with all major browsers, including IE9.
Draw SVG to Canvas with canvas.drawImage()
Canvas becomes write-only! (
origin-clean
dirty
)
Works with Webkit (Chrome and Safari).
Exporting as a file
Canvas→PNG
Right-click→Save as… (Firefox supports it)
Canvas.toDataURL
(
new window
)
SVG→PNG
Server-side
SVG.toDataURL('image/png')
SVG→SVG file
Right-click→Save as… (IE9 supports it)
SVG.toDataURL('image/svg+xml')
(
new window
)
Legend (based on background-color):
This won't work anymore, because Canvas'
origin-clean
is
dirty
. Maybe you broke it?
Beware! This will set Canvas'
origin-clean
dirty
, making Canvas write-only.
This
might
set Canvas'
origin-clean
dirty
, depending on whether you're transferring images inside SVG data.
Dare to look
the full demo page
?