Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML5 canvas, resize a background image

Tags:

html

image

canvas

I have a canvas thas is created dynamically, so width and height are always differents.

I have a background image i want to put on this canvas, so i just add in CSS :

canvas { background:url(/URL/background-canvas.jpg) }

But, how can i auto resize the image to the size of my canvas ? Thanks !

like image 376
Clément Andraud Avatar asked Oct 24 '25 18:10

Clément Andraud


1 Answers

I believe you can do something like this:

canvas { 
    background: url('/URL/background-canvas.jpg');
    background-size: 100% 100%;
}

See this for more info on it.

like image 65
Jason Avatar answered Oct 26 '25 08:10

Jason



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!