I have a Canvas element that is inside a container div. When the user selects an image from his machine, this image should be displayed on the canvas. I want the canvas to be as large as possible, but at the same time keep the aspect ratio of the image. I know neither the aspect ratio of the image, nor the size of the div container, since this refers to the size of the user's screen / window.
If I set the maximum width and maximum height, for example 100%, the canvas does not fill the container if the selected image is smaller than the container. If I set the width and height instead of max-width and max-height, the canvas does not maintain the aspect ratio.
Does anyone have an idea how to solve this?
source
share