You're not really doing anything wrong. More like doing the right things in a confused manner. The only really wrong thing that jumps out at me is:
Code:
canvasImage2.src = drawCanvas();
The drawCanvas function has no return value, so that's the same as:
Code:
canvasImage2.src = 'undefined';
So of course you see no image. The first image may or may not appear depending upon the browser and whether or not the image is loaded yet. Try (using the onload event of the image to trigger the drawing of the canvas):
Code:
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Image and text</title>
<style id="jsbin-css">
*{margin:0; padding:0;}
body{
background:#000;
color:#fff;
}
canvas{
border-left:2px solid #000;
border-right:2px solid #000;
border-top:2px solid #000;
-webkit-transition:1s;
transition:1s;
margin:40px auto;
display:block;
}
</style>
</head>
<body>
<script>
var canvas = document.createElement('canvas'),
ctx = canvas.getContext('2d');
canvas.width = 500;
canvas.height = 500;
canvas.style.borderRadius = "15px";
document.body.appendChild(canvas); // Add canvas to DOM
// GRAPHICS
var canvasImage = new Image();
// GRAPHICS TO CANVAS ///////////////////
function drawCanvas(){
ctx.drawImage(canvasImage, 0, 0);
ctx.font = '90px Calibri';
ctx.textAlign = 'center';
ctx.fillStyle = 'rgba(70, 70, 255, 0.7)';
ctx.fillText('Some text', canvas.width/2, canvas.height/2);
}
canvasImage.onload = drawCanvas;
canvasImage.src = 'S1110.jpg';
</script>
<a href="send.php" id="send-button" class="btn btn-info">send</a>
</body>
</html>
Here's a demo:
http://home.comcast.net/~jscheuer1/s...its/canvas.htm
Bookmarks