Add 'clone' method to snapshot an instance

Cloned instances share a common input
Allows multiple output Streams to use a single input Stream
This commit is contained in:
Lovell Fuller
2015-06-23 13:24:32 +01:00
parent 1091be374e
commit 86490bedfb
4 changed files with 93 additions and 1 deletions

View File

@@ -163,6 +163,15 @@ var pipeline = sharp()
readableStream.pipe(pipeline);
```
```javascript
var pipeline = sharp().rotate();
pipeline.clone().resize(800, 600).pipe(firstWritableStream);
pipeline.clone().extract(20, 20, 100, 100).pipe(secondWritableStream);
readableStream.pipe(pipeline);
// firstWritableStream receives auto-rotated, resized readableStream
// secondWritableStream receives auto-rotated, extracted region of readableStream
```
```javascript
sharp('input.png')
.rotate(180)
@@ -347,6 +356,14 @@ Do not process input images where the number of pixels (width * height) exceeds
`pixels` is the integral Number of pixels, with a value between 1 and the default 268402689 (0x3FFF * 0x3FFF).
#### clone()
Takes a "snapshot" of the instance, returning a new instance.
Cloned instances inherit the input of their parent instance.
This allows multiple output Streams
and therefore multiple processing pipelines
to share a single input Stream.
### Image transformation options
#### resize(width, [height])