Let's say I have cat.png
at 800x600 pixel.
Then I put it into img and apply CSS object-fit like below:
#cat {
width: 100px;
height: 100px;
object-fit: cover;
}
<img src="cat.png" id="cat">
Now I have on screen a 100x100 image.
How to transfer this final result into canvas, so that I could get the dataUrl and save as cat_thumb.png
at 100x100 pixel?
These codes simply ignore the CSS applied to the img:
var c = document.getElementById("myCanvas");
var ctx = c.getContext("2d");
var img = document.getElementById("cat");
ctx.drawImage(img,0,0,100,100);
console.log(c.toDataURL());