npm install img-converter
import ImgConverter from 'img-converter'
ImgConverter.convert(sourceImageFile, targetImageFormat);
<input type='file' accept=".jpg, .png, .gif" onchange="convertImg(this)" />
import ImgConverter from 'img-converter'
async function convertImg(input) {
let sourceImageFile = input.files[0];
let targetImageFormat = 'png'
let convertedImgDataObj = await ImgConverter.convert(sourceImageFile, targetImageFormat);
}
This convert function will return a converted image data object which includes image name, format and base64 image string.
function downloadImg(convertedImgDataObj) {
let a = document.createElement("a");
a.href = convertedImgDataObj.data;
a.download = convertedImgDataObj.name + "." + convertedImgDataObj.format;
a.click();
}
MIT