2.0.2 • Published 7 years ago

@petitchevalroux/base64-img-to-url v2.0.2

Weekly downloads
1
License
GPL-3.0
Repository
github
Last release
7 years ago

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) => {

    }
};
2.0.2

7 years ago

2.0.1

7 years ago

2.0.0

7 years ago

1.0.0

7 years ago