Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<body>
<img id="canvas-to-data"/>
<script>
canvas = document.createElement('canvas');
canvas.width=100;
canvas.height=100;
var ctx = canvas.getContext('2d');
ctx.fillStyle = 'green';
ctx.fillRect(0, 0, 50, 100);
ctx.fillStyle = 'red';
ctx.fillRect(50, 0, 50, 100);
data = canvas.toDataURL("image/jpeg");
document.getElementById('canvas-to-data').src = data;
</script>
</body>
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
anonymouspro
0viewers