mxr-image-utils
TypeScript icon, indicating that this package has built-in type declarations

1.0.8 • Public • Published

mxr-image-utils

A image utils library.

The idea is that it be a image-utils library with a lot of functions for a lot of situations. For a while, it has just a base64's module.

Below is how to use the library main functions:

How to use:

import { ImageUtils } from "mxr-image-utils/base64";

async function convertImage(e){
    await ImageUtils.blobToBase64({blob: e.target.files[0]}); // convert a blob object to a base64 string
}

/**
 * return: 
     { 
     * base64:"iVBORw0KGgoAAAANSUhEUgAAAe...", 
     * completeBase64: "data:image/png;base64,iVBO...",
     * fileType: "png"
     * }
     */

async function convertUrlImage(url){
    await ImageUtils.urlToBase64(url) //convert a url to a base64 string;

    // this function return the same instance of object that the blobToBase64 function
}

You can, talking about blobToBase64 method, define which types will be accepts.

          await ImageUtils.blobToBase64({
              blob: event.target.files[0],
              acceptedTypes: ["svg+xml", "png", "jpeg"]
              });

There is anothers functions, which can be utils:

    ImageUtils.isImage(base64) /// verify if a base64 is from a image
    ImageUtils.isBlob(blob) //verify is the param is really a blob

    //both return a boolean

🤘

Package Sidebar

Install

npm i mxr-image-utils

Weekly Downloads

1

Version

1.0.8

License

GPL-3.0

Unpacked Size

63.7 kB

Total Files

32

Last publish

Collaborators

  • matheusxreis