img-converter

1.0.3 • Public • Published

img-converter

A simple image conversion tool to convert jpg, png and gif image.

DEMO

Install

npm install img-converter

Usage

import ImgConverter from 'img-converter'

ImgConverter.convert(sourceImageFile, targetImageFormat);

Example Code

<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.
This base64 image string can be used to download the converted image.
function downloadImg(convertedImgDataObj) {
    let a = document.createElement("a");
    a.href = convertedImgDataObj.data;
    a.download = convertedImgDataObj.name + "." + convertedImgDataObj.format;
    a.click();
}

License

MIT

Package Sidebar

Install

npm i img-converter

Weekly Downloads

93

Version

1.0.3

License

MIT

Unpacked Size

4.36 kB

Total Files

4

Last publish

Collaborators

  • sdn101