I have a script that renders a image onto a canvas context. I want to change the width of the canvas to match the dimensions of the image. I use the following script to do so:
var c = document.getElementById("c");
var ctx = c.getContext("2d");
function loadImage(url){
var img = new Image();
img.src = url;
return img;
};
var image = loadImage("images/bird.png");
c.width = image.width + "px";
c.height = image.height + "px";
{...}
However, the canvas' dimentions are set to "0", even if I go into the console and type c.width = "10px"
or something around those lines.