javascript - Change size of an image loaded from URL -
how modify size of image here?:
var image = new image(); image.src = 'http://www.ziiweb.com/images/logo.png'; image.width = 200; //this not modifying width of image $('canvas').css({ background: 'url(' + image.src + ')' });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <canvas id="mycanvas" width="200" height="100" style="border:1px solid #000000;"> </canvas>
you inserting image background, use background-size.
var image = new image(); image.src = 'http://www.ziiweb.com/images/logo.png'; $('canvas').css({ backgroundimage: 'url(' + image.src + ')', backgroundsize: "100%" });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <canvas id="mycanvas" width="200" height="100" style="border:1px solid #000000;"> </canvas>