The HTML page I try to do is to upload image to canvas, put a watermark on that image, then download the image with the watermark as one png file. The current problem is I can upload the image to the canvas and put the watermark but I can't download the canvas.
I've already tried some solution on the internet including stackoverflow. Fidesaver.js didn't works for that. so here is the code:(The watermark in the code is just random 240x240 image i found in google)
The project page on Glitch.com seems not work anymore, so I put the code in the code snippet:
Upper image:<br>
<img src="https://micolsalomone.com/wp-content/uploads/2018/04/preloader-logo-240x240.png" width="150px" alt="Example image" id="wm" >
<input type="file" id="imageLoader" name="imageLoader"/><br>
<canvas id="imageCanvas"></canvas>
<script type="text/javascript">
var wm=document.getElementById("wm");
var imageLoader = document.getElementById('imageLoader');
imageLoader.addEventListener('change', handleImage, false);
var canvas = document.getElementById('imageCanvas');
var ctx = canvas.getContext('2d');
function handleImage(e){
var reader = new FileReader();
reader.onload = function(event){
var img = new Image();
img.crossOrigin = '';
img.onload = function(){
canvas.width = 240;
canvas.height = 240;
ctx.drawImage(img,0,0,240,240);
ctx.drawImage(wm,0,0,240,240);
}
img.src = event.target.result;
}
reader.readAsDataURL(e.target.files[0]);
}
</script>