JSPM

base64js-es6

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 4
  • Score
    100M100P100Q32383F
  • License MIT

Package for encoding images to base64 images and resizing base64 images

Package Exports

  • base64js-es6

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (base64js-es6) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Base64js-ES6

Package for encoding images to base64 images and resizing base64 images 🔥

Install

npm install base64js-es6 // yarn add base64js-es6

Usage

The functions are Promise based and can be used as ES6 Modules.

Encode to base64

import EncodeToBase64 from 'base64js-es6' // Default export
import { getBase64 } from 'base64js-es6' // Named export for encoding to base64

Example

// With <input type="file" name="files[]" onchange="ImageOnChange" />
function ImageOnChange(e) {
    const file = e.target.files;

    // getBase64(src of file)
    getBase64(file[0]).then((response) => {
        // Will log the base64 string
        console.log(response)
    });
}

Resize base64

import { getBase64, resizeBase64 } from 'base64js-es6' // Named exports for encoding and resizing

Example

// With <input type="file" name="files[]" onchange="ImageOnChange" />
function ImageOnChange(e) {
    const file = e.target.files;

    getBase64(file[0]).then((response) => {
        
        // resizeBase64(src of file, width, height)
        resizeBase64(response, 250, 250).then((result) => {
            // Will log a new base64 string
            // Do whatever what you want with this string
            console.log(result);
        });
    });
}

Contribution

Feel free to contribute to this package. If you have any questions you can reach out to me on twitter 😄

License

MIT