2ndGAB 2ndGAB - 6 months ago 20
HTML Question

Cannot correctly resize an image at less than 60%

I've implemented a background color modification based on this post

But I want to modify my image size and when I set it below 60%, the image is cropped instead of being resized.

I saw that the problem come from the function

colorImage
but I cannot understand why.

Could you have look at his fiddle and change the width of
img_top
to 50% for example to see the problem?

Answer

You needed to pass the image width/height when using drawImage

http://jsfiddle.net/gRoberts/e0nwnhet/11/

var ctx = canvas.getContext("2d");
ctx.drawImage(imgElement,0,0,canvas.width,canvas.height);