image-to-base64

2.2.0last stable release 4 years ago
Complexity Score
Low
Open Issues
1
Dependent Projects
47
Weekly Downloadsglobal
144,091

License

  • MIT
    • Yesattribution
    • Permissivelinking
    • Permissivedistribution
    • Permissivemodification
    • Nopatent grant
    • Yesprivate use
    • Permissivesublicensing
    • Notrademark grant

Downloads

Loading Weekly Download Data

Readme

image-to-base64

Generate a base64 code from an image through a URL or a path.

About

It’s a thing you can use in many situations, for example you can just save the base64 string in your database and increment it in the front-end with the <img> tag in HTML.

Getting Started

Installation:

npm i -S image-to-base64

Code Example:

const imageToBase64 = require('image-to-base64');
//or
//import imageToBase64 from 'image-to-base64/browser';

imageToBase64("path/to/file.jpg") // Path to the image
    .then(
        (response) => {
            console.log(response); // "cGF0aC90by9maWxlLmpwZw=="
        }
    )
    .catch(
        (error) => {
            console.log(error); // Logs an error if there was one
        }
    )

Remember that you can also use an image URL as a parameter.

Code Example:

imageToBase64("https://whatever-image/") // Image URL
    .then(
        (response) => {
            console.log(response); // "iVBORw0KGgoAAAANSwCAIA..."
        }
    )
    .catch(
        (error) => {
            console.log(error); // Logs an error if there was one
        }
    )

Browser Usage

You can import image-to-base64 using the <script> tag in HTML.

Code Example:

<script src="node_modules/image-to-base64/image-to-base64.min.js"></script>

Now you can use the module normally as in the JS examples above, but you can only use a URL and not a path.

LICENSE

MIT © 2017 RENAN.BASTOS

Dependencies

Loading dependencies...

CVE IssuesActive
0
Scorecards Score
3.40
Test Coverage
No Data
Follows Semver
Yes
Github Stars
133
Dependenciestotal
3
DependenciesOutdated
1
DependenciesDeprecated
0
Threat Modelling
No
Repo Audits
No

Learn how to distribute image-to-base64 in your own private NPM registry

npm config set registry  https://npm.cloudsmith.com/owner/repo
Processing...
Done
npm install image-to-base64
Processing...
Done

12 Releases

NPM on Cloudsmith

Getting started with NPM on Cloudsmith is fast and easy.