Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

ascii

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

ascii - npm Package Compare versions

Comparing version 0.0.1 to 0.1.0

example/demo.jpg

63

index.js

@@ -8,39 +8,40 @@ // ___ _ _

// @author: [turing](http://guoyu.me);
// @desc: convert jpg/png/gif to ascii arts based on node-canvas.
var fs = require('fs'),
Canvas = require('canvas'),
ascii = require('./ascii');
// @desc: convert pictures to ascii arts based on node-canvas
var Ascii = function(src, params) {
this.src = src;
var fs = require('fs');
var Canvas = require('canvas');
var ascii = require('./lib/ascii');
module.exports = Ascii;
function Ascii(src, params) {
this.src = src;
}
Ascii.prototype.load = function(callback) {
if (this.src) {
fs.readFile(this.src, function(err, img){
callback(err, img);
});
} else {
callback(new Error('src picture required.'))
}
}
if (this.src)
return fs.readFile(this.src, callback);
return callback(new Error('src picture required.'))
};
Ascii.prototype.convert = function(type, callback) {
var t = (type && typeof(type) === 'string') ? type : 'cli',
cb = (typeof(type) === 'function' && !callback) ? type : callback;
this.load(function(err, img){
if (!err) {
var pic = new Canvas.Image;
pic.src = img;
var cv = new Canvas(pic.width, pic.height),
ctx = cv.getContext('2d');
ctx.drawImage(pic, 0, 0, pic.width, pic.height);
cb(null, ascii.init(t, ctx, pic));
} else {
cb(err);
}
});
}
var t = (type && typeof(type) === 'string') ? type : 'cli';
var cb = (typeof(type) === 'function' && !callback) ? type : callback;
this.load(function(err, img) {
if (err) return cb(err);
var pic = new Canvas.Image;
pic.src = img;
var cv = new Canvas(pic.width, pic.height);
var ctx = cv.getContext('2d');
ctx.drawImage(pic, 0, 0, pic.width, pic.height);
cb(null, ascii.init(t, ctx, pic));
});
};
module.exports = Ascii;
Ascii.fromBuffer = function(buffer) {
var instance = new Ascii();
instance.load = function(callback) {
callback(null, buffer);
};
return instance;
};
{
"name": "ascii",
"version": "0.0.1",
"description": "convert jpg/png/gif to ascii arts based on node-canvas",
"version": "0.1.0",
"description": "convert pictures to ascii arts based on node-canvas",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"example": "node example/index.js"
},

@@ -18,7 +18,10 @@ "repository": {

],
"author": "turing",
"author": "turing <o.u.turing@gmail.com>",
"license": "MIT",
"bugs": {
"url": "https://github.com/turingou/ascii/issues"
},
"dependencies": {
"canvas": ">= 1.1.0"
}
}

@@ -1,12 +0,13 @@

## ascii ![npm](https://badge.fury.io/js/ascii.png)
## Ascii ![npm](https://badge.fury.io/js/ascii.png)
convert jpg/png/gif to ascii arts based on node-canvas
![screenshot](http://ww3.sinaimg.cn/mw1024/61ff0de3gw1e903qhbyt8j20kl0f5768.jpg)
### Installation
````
```bash
$ npm install ascii
````
```
### Example
````javascript
```javascript
var Ascii = require('ascii');

@@ -17,3 +18,3 @@ var pic = new Ascii('demo.png');

pic.convert(function(err, result) {
console.log(result);
console.log(result);
});

@@ -23,11 +24,8 @@

pic.convert('html', function(err, html){
console.log(html);
// then save it
require('fs').saveFileSync('demo.html',html);
console.log(html);
// then save it
require('fs').writeFileSync('demo.html',html);
});
````
```
### API
check this file: `index.js`
### Contributing

@@ -34,0 +32,0 @@ - Fork this repo

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc