@petitchevalroux/base64-img-to-url

2.0.2 • Public • Published

base64-img-to-url

Convert base64 encoded image to url in html

In order to convert url to base64 images in html see url-to-base64-img

Install

npm install @petitchevalroux/base64-img-to-url

Usage

Example code

const Base64Img = require("@petitchevalroux/base64-img-to-url");
    base64Img = new Base64Img({
        upload: () => {
            this.counter = (this.counter || 0) + 1;
            return Promise.resolve("https://example.com/img/" +
                this.counter);
        }
    });
    base64Img.replace("<img src=\"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+P+/HgAFhAJ/wlseKgAAAABJRU5ErkJggg==\">")
    .then(html=>{
        console.log(html);
    });

Output

<img src="https://example.com/img/1">

Uploader

Uploader requirements

Uploader instance must have an upload member function. This function must return a promised string containing the image url.

Uploader skeleton

const uploader = {
    /**
     * Handle upload
     * @param {buffer} buffer image buffer
     * @param {string} mimeType image mime type
     * @returns {Promise<string>} image url
     */
    upload: (buffer,mimeType) => {

    }
};

Readme

Keywords

Package Sidebar

Install

npm i @petitchevalroux/base64-img-to-url

Weekly Downloads

0

Version

2.0.2

License

GPL-3.0

Unpacked Size

12.9 kB

Total Files

10

Last publish

Collaborators

  • petitchevalroux