https://github.com/lestoni/base64image-to-file
Create an image file from a base64 encoded image ie data-url string.
https://github.com/lestoni/base64image-to-file
Last synced: about 1 year ago
JSON representation
Create an image file from a base64 encoded image ie data-url string.
- Host: GitHub
- URL: https://github.com/lestoni/base64image-to-file
- Owner: lestoni
- License: mit
- Created: 2015-05-27T18:20:28.000Z (about 11 years ago)
- Default Branch: master
- Last Pushed: 2015-09-16T21:41:33.000Z (over 10 years ago)
- Last Synced: 2024-04-23T22:10:26.953Z (about 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 133 KB
- Stars: 6
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# base64image-to-file
[](https://travis-ci.org/lestoni/base64image-to-file)
[](https://nodei.co/npm/base64image-to-file/)
The module takes a base64 encoded image string(i.e data-url) and creates an image file from it.
## Install
```sh
$ npm install base64image-to-file --save
```
## Usage
```javascript
var base64ImageToFile = require('base64image-to-file');
var base64Image = 'data:image/gif;base64,R0lGODdhMgAyAOM...';
// create an image with the a given name ie 'image'
base64ImageToFile(base64Image, '/tmp/', 'image', function(err) {
if(err) {
return console.error(err);
}
console.log(imgPath);
});
// create an image with the a random name(basically hex string)
base64ImageToFile(base64Image, '/tmp/', function(err) {
if(err) {
return console.error(err);
}
console.log(imgPath);
});
```
## API
### base64ImageToFile(base64String, dirPath [, imageName], cb)
__base64String__
Type: String
This should be a base64 encoded string.
__dirPath__
Type: String
Directory to create the image in.
__imageName(Optional)__
Type: String
Name to give the created file, otherwise it is given a random name
__cb__
Type: Function
Callback function with signature `cb(err, imgPath)`.
## License
MIT.