I'm looking to make a canvas containing an image that's dynamically sized and can be interacted with. Since making the canvas dynamically sized will cause issues with the pixel ratio, I must start from the other end; dynamically sizing the image, then passing the image into the canvas to set the canvas width and height.
I'm using getComputedStyle()
and getPropertyValue()
to retrieve the dimensions of the image inside the JavaScript file. However, the issue is that I cannot retrieve the computed style of the image if I only want to show the canvas.
If I have #image { display: none; width: 100%; }
, calling getPropertyValue("width")
on my image will return 100
rather than the actual computed size of the image. Removing display: none
allows me to retrieve the actual dimensions, but then I have two copies, one inside the canvas and one regular img.