0.1.2 • Published 2 years ago

js-convert-images v0.1.2

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
2 years ago

ConvertImage

Convert images to another type with typescript support

Usage

import { ConvertImage } from "convert-image";

const converter = new ConvertImage();

const options = {
  name: "random-image",
  download: true,
  width: 400,
  height: 400,
  type: "webp",
};

const file = document.querySelect('input[type="file"]').files[0];

converter
  .convertImageFromUrl("https://i.picsum.photos/id/376/200/300.jpg", options)
  .then((data) => {
    console.log(data);
  });

converter.convertImageFromFile(file, options).then((data) => {
  console.log(data);
});

Functions

convertImageFromUrl(url, options)

Make sure the url called by convertImageFromUrl has no CORS issue

convertImageFromFile(file, options)

File is a file given by an input type file (ex: document.querySelect('inputtype="file"').files0)

Width & Height

This values let you set width and height value, the image will be scaled due to this values

Types

Possible types: webp, png, jpeg, gif, bmp