Skip to content

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

License

Notifications You must be signed in to change notification settings

suvro404/img-converter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

img-converter

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

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

About

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published