Hey,
I’ve been working on a project that allows a user to upload an image to canvas.
But as user upload an image, It goes out of the mobile screen and a horizontal scroll bar appears.
Please help me what code I need to put in to make the image responsive with canvas and also fit in all devices including mobile.
<canvas width= "600px" height = "300px" id="canvas" ></canvas><br>
<input type="file" id="UploadFile" style="margin-left: 10px; "><br>
<div id="preview"></div>
<script>
var $preview= $("#preview");
var canvas = $('#canvas')[0];
var context = canvas.getContext('2d');
$("#UploadFile").change(function (e) {
var F = this.files[0];
var reader = new FileReader();
reader.onload = imageIsLoad;
reader.readAsDataURL(F);
});
function imageIsLoad(e) {
var image = new Image();
image.onload = function(){
canvas.width = this.width;
canvas.height = this.height;
context.drawImage(this, 0,0);
};
image.src = e.target.result;
}