My goal is to have the user upload a local image. I draw this image in a canvas element. On top of this canvas element, I create another canvas, which I use to draw boxes on, so that the boxes overlay the uploaded image.
I want the image to be uploaded in a specific size, say maximum 100 width and maximum 100 height. It's not enough for me to have the image merely displayed at max-height and max-width: 100, it physically needs to be resized during the upload process. Because if I put a super big picture in a say 100x100 canvas, then the boxes on top of it become very small and I need them to be the same size regardless what size the image in the canvas is.
Below is the code: HTML:
<div style="position: relative;"> <canvas id="can" style="position: absolute; left: 0; top: 0; z-index: 0;max-width:80%;"></canvas> <canvas id="box" style="position: absolute; left: 0; top: 0; z-index: 1;max-width:80%;"></canvas> </div> <input type="file" multiple="false" accept="image/*" id="finput" onchange="upload()"> And JS:
function upload() { //Get input from file input var fileinput = document.getElementById("finput"); //Make new SimpleImage from file input image = new SimpleImage(fileinput); //Get canvas var canvas = document.getElementById("can"); //Draw image on canvas image.drawTo(canvas); } I use the simpleImage library because it lets me extract RGB values of the image.