IMAGE TO PNG

function convertToPNG() { let input = document.getElementById(‘imageInput’).files[0]; if (input) { let img = new Image(); let reader = new FileReader(); reader.onload = function(e) { img.src = e.target.result; img.onload = function() { let canvas = document.getElementById(“canvas”); let ctx = canvas.getContext(“2d”); canvas.width = img.width; canvas.height = img.height; ctx.drawImage(img, 0, 0); let pngData = canvas.toDataURL(“image/png”); let a = document.createElement(“a”); a.href = pngData; a.download = “converted.png”; a.click(); } }; reader.readAsDataURL(input); } }

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top