Comparing version 0.0.1 to 0.1.0
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
10
115
2
82486
1
62
1
+ Addedcanvas@>= 1.1.0
+ Added@mapbox/node-pre-gyp@1.0.11(transitive)
+ Addedabbrev@1.1.1(transitive)
+ Addedagent-base@6.0.2(transitive)
+ Addedansi-regex@5.0.1(transitive)
+ Addedaproba@2.0.0(transitive)
+ Addedare-we-there-yet@2.0.0(transitive)
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedcanvas@2.11.2(transitive)
+ Addedchownr@2.0.0(transitive)
+ Addedcolor-support@1.1.3(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedconsole-control-strings@1.1.0(transitive)
+ Addeddebug@4.3.7(transitive)
+ Addeddecompress-response@4.2.1(transitive)
+ Addeddelegates@1.0.0(transitive)
+ Addeddetect-libc@2.0.3(transitive)
+ Addedemoji-regex@8.0.0(transitive)
+ Addedfs-minipass@2.1.0(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedgauge@3.0.2(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedhas-unicode@2.0.1(transitive)
+ Addedhttps-proxy-agent@5.0.1(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedis-fullwidth-code-point@3.0.0(transitive)
+ Addedmake-dir@3.1.0(transitive)
+ Addedmimic-response@2.1.0(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedminipass@3.3.65.0.0(transitive)
+ Addedminizlib@2.1.2(transitive)
+ Addedmkdirp@1.0.4(transitive)
+ Addedms@2.1.3(transitive)
+ Addednan@2.22.0(transitive)
+ Addednode-fetch@2.7.0(transitive)
+ Addednopt@5.0.0(transitive)
+ Addednpmlog@5.0.1(transitive)
+ Addedobject-assign@4.1.1(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedreadable-stream@3.6.2(transitive)
+ Addedrimraf@3.0.2(transitive)
+ Addedsafe-buffer@5.2.1(transitive)
+ Addedsemver@6.3.17.6.3(transitive)
+ Addedset-blocking@2.0.0(transitive)
+ Addedsignal-exit@3.0.7(transitive)
+ Addedsimple-concat@1.0.1(transitive)
+ Addedsimple-get@3.1.1(transitive)
+ Addedstring-width@4.2.3(transitive)
+ Addedstring_decoder@1.3.0(transitive)
+ Addedstrip-ansi@6.0.1(transitive)
+ Addedtar@6.2.1(transitive)
+ Addedtr46@0.0.3(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwebidl-conversions@3.0.1(transitive)
+ Addedwhatwg-url@5.0.0(transitive)
+ Addedwide-align@1.1.5(transitive)
+ Addedwrappy@1.0.2(transitive)
+ Addedyallist@4.0.0(transitive)