Socket
Socket
Sign inDemoInstall

img-converter

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

img-converter

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


Version published
Maintainers
1
Weekly downloads
29
increased by38.1%
Install size
4.26 kB

Weekly downloads

Readme

Source

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

Keywords

FAQs

Last updated on 26 Apr 2021

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc