imagemagick-stream
Advanced tools
Comparing version 2.0.0 to 3.0.0
26
index.js
var PassThrough = require('stream').PassThrough; | ||
var spawn = require('child_process').spawn; | ||
var Duplex = require('reduplexer'); | ||
var Duplexify = require('duplexify'); | ||
var util = require('util'); | ||
@@ -33,7 +33,4 @@ var isError = util.isError; | ||
this.in = new PassThrough(); | ||
this.out = new PassThrough(); | ||
Duplexify.call(this); | ||
Duplex.call(this, this.in, this.out); | ||
if (src) this.from(src); | ||
@@ -44,6 +41,6 @@ setImmediate(this.spawn); | ||
/** | ||
* Inherit from `Duplex` | ||
* Inherit from `Duplexify` | ||
*/ | ||
inherit(ImageMagick, Duplex); | ||
inherit(ImageMagick, Duplexify); | ||
@@ -215,2 +212,3 @@ /** | ||
* @param {String} path | ||
* @return {Stream} writable stream | ||
* @api public | ||
@@ -223,3 +221,3 @@ */ | ||
this.pipe(write); | ||
return this; | ||
return write; | ||
}; | ||
@@ -236,10 +234,10 @@ | ||
var stdout = proc.stdout; | ||
stdout.on('error', this.onerror); | ||
this.setReadable(stdout); | ||
var stdin = proc.stdin; | ||
stdin.on('error', this.onerror); | ||
this.in.pipe(stdin); | ||
this.setWritable(stdin); | ||
var stdout = proc.stdout; | ||
stdout.on('error', this.onerror); | ||
stdout.pipe(this.out); | ||
var stderr = proc.stderr; | ||
@@ -299,2 +297,2 @@ stderr.on('data', this.onerror); | ||
this.emit('error', err); | ||
}; | ||
}; |
{ | ||
"name": "imagemagick-stream", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "Streaming Imagemagick api", | ||
@@ -11,4 +11,7 @@ "keywords": [ | ||
"author": "Eivind Fjeldstad", | ||
"scripts": { | ||
"test": "make test" | ||
}, | ||
"dependencies": { | ||
"reduplexer": "0.0.2" | ||
"duplexify": "3.4.2" | ||
}, | ||
@@ -18,5 +21,2 @@ "devDependencies": { | ||
}, | ||
"scirpts": { | ||
"test": "make test" | ||
}, | ||
"repository": { | ||
@@ -23,0 +23,0 @@ "type": "git", |
@@ -13,9 +13,8 @@ # imagemagick-stream | ||
var im = require('imagemagick-stream'); | ||
var in = fs.createReadStream('image.png'); | ||
var out = fs.createWriteStream('image-resized.png'); | ||
var read = fs.createReadStream('image.png'); | ||
var write = fs.createWriteStream('image-resized.png'); | ||
var resize = im().resize('200x200').quality(90); | ||
read.pipe(resize).pipe(write); | ||
in.pipe(resize).pipe(out); | ||
// Alternatively | ||
@@ -25,3 +24,3 @@ im('image.png') | ||
.quality(90) | ||
.pipe(out); | ||
.pipe(write); | ||
@@ -36,3 +35,3 @@ // Or | ||
For freehand settings and operations, use `.op()` and `.set()`. | ||
See the [imagemagick docs](http://www.imagemagick.org/script/convert.php) a list of available options. | ||
See the [imagemagick docs](http://www.imagemagick.org/script/convert.php) for a list of available options. | ||
@@ -44,7 +43,19 @@ ``` js | ||
.resize('200x200') | ||
.op('gaussian-blur', 0.05); | ||
.op('gaussian-blur', 0.05) | ||
.to('image-resized.png'); | ||
``` | ||
**NOTE:** You shold listen to the `finish` event on the writable stream you're piping to, not the stream from ImageMagick: | ||
```js | ||
var read = fs.createReadStream('image.png'); | ||
var write = fs.createWriteStream('image-resized.png'); | ||
var resize = im().resize('200x200').quality(90); | ||
write.on('finish', function () { | ||
// finished writing | ||
}); | ||
``` | ||
## License | ||
MIT |
@@ -17,6 +17,7 @@ var assert = require('assert'); | ||
var img = im(); | ||
var write = fs.createWriteStream(__dirname + '/test-resized.jpg'); | ||
fs.createReadStream(__dirname + '/test.jpg').pipe(img); | ||
img.pipe(fs.createWriteStream(__dirname + '/test-resized.jpg')); | ||
img.on('finish', function () { | ||
assert(fs.existsSync(__dirname + '/test-resized.jpg')); | ||
img.pipe(write); | ||
write.on('finish', function () { | ||
assert(fs.statSync(__dirname + '/test-resized.jpg').size > 0); | ||
fs.unlinkSync(__dirname + '/test-resized.jpg'); | ||
@@ -40,5 +41,6 @@ done(); | ||
var img = im().from(__dirname + '/test.jpg'); | ||
img.pipe(fs.createWriteStream(__dirname + '/test-resized.jpg')); | ||
img.on('finish', function () { | ||
assert(fs.existsSync(__dirname + '/test-resized.jpg')); | ||
var write = fs.createWriteStream(__dirname + '/test-resized.jpg'); | ||
img.pipe(write); | ||
write.on('finish', function () { | ||
assert(fs.statSync(__dirname + '/test-resized.jpg').size > 0); | ||
fs.unlinkSync(__dirname + '/test-resized.jpg'); | ||
@@ -52,6 +54,7 @@ done(); | ||
it('should write to the given path', function (done) { | ||
var img = im().to(__dirname + '/test-resized.jpg'); | ||
var img = im() | ||
var write = img.to(__dirname + '/test-resized.jpg'); | ||
fs.createReadStream(__dirname + '/test.jpg').pipe(img); | ||
img.on('finish', function () { | ||
assert(fs.existsSync(__dirname + '/test-resized.jpg')); | ||
write.on('finish', function () { | ||
assert(fs.statSync(__dirname + '/test-resized.jpg').size > 0); | ||
fs.unlinkSync(__dirname + '/test-resized.jpg'); | ||
@@ -261,2 +264,2 @@ done(); | ||
}) | ||
}); | ||
}); |
Sorry, the diff of this file is not supported yet
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
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
44420
469
58
+ Addedduplexify@3.4.2
+ Addedduplexify@3.4.2(transitive)
+ Addedend-of-stream@1.0.0(transitive)
+ Addedisarray@1.0.0(transitive)
+ Addedonce@1.3.3(transitive)
+ Addedprocess-nextick-args@2.0.1(transitive)
+ Addedreadable-stream@2.3.8(transitive)
+ Addedsafe-buffer@5.1.2(transitive)
+ Addedstring_decoder@1.1.1(transitive)
+ Addedutil-deprecate@1.0.2(transitive)
+ Addedwrappy@1.0.2(transitive)
- Removedreduplexer@0.0.2
- Removedisarray@0.0.1(transitive)
- Removedreadable-stream@1.0.34(transitive)
- Removedreduplexer@0.0.2(transitive)
- Removedstring_decoder@0.10.31(transitive)