var sourceImage = document.getElementById('source-image'); var targetCanvas = document.getElementById('target-canvas'); var pica = window.pica(); // Set the canvas dimensions to match the source image dimensions targetCanvas.width = sourceImage.width; targetCanvas.height = sourceImage.height; // Convert the image to PNG format using pica pica.resizeCanvas(sourceImage, targetCanvas, { unsharpAmount: 80, unsharpRadius: 0.6, unsharpThreshold: 2 }).then(function(result) { // Save the converted PNG image var dataURL = targetCanvas.toDataURL('image/png'); var link = document.createElement('a'); link.download = 'converted-image.png'; link.href = dataURL; document.body.appendChild(link); link.click(); document.body.removeChild(link); });