JSFiddle - React, Tailwind, and code Playground
HTML
<input type="file" onchange="processfile(this)">
JavaScript
function processfile(el) {
const file = el.files[0];
const url = URL.createObjectURL(file);
const img = new Image();
img.src = url;
img.onload = function() {
URL.revokeObjectURL(url);
const canvas = document.createElement('canvas');
canvas.width = 200;
canvas.height = 200;
const ctx = canvas.getContext('2d');
ctx.drawImage(img, 0, 0, 200, 200);
canvas.toBlob(function(blob) {
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'image.jpg';
a.click();
}, 'image/jpeg', 0.8);
}
}