1

I am currently developing an app allowing users to draw shapes top of an image.

I am using canvas with background-image set to url("uploaded image_url").

I am having trouble getting canvas size fitted to background image size and to the viewport size at once.

Consider the following snipper - a lot of the lower image is cropped:

.drawer-area {
  width: 90%;
  background-image: url("https://i.picsum.photos/id/430/200/300.jpg?hmac=souGSmvwQ6KlJgthGYBGSWB22Y7MpK5xlgLYwvtbXzg");
  background-size: cover;
}
<canvas class="drawer-area"></canvas>

Note, I don't know the size of the image beforehand. I am using background-size: cover and width: 90%, but it doesn't do the trick. Any advice?

Daniel_Knights
  • 7,940
  • 4
  • 21
  • 49

1 Answers1

0

Have you tried using something like this on your style sheet? background: url("uploaded image_url") center center/ cover no-repeat; This should make the image fit into the container you've assigned it to, hope it helps!

JardimJ
  • 1
  • 2