3.5 KiB
clone
Take a "snapshot" of the Sharp 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.
Examples
const pipeline = sharp().rotate();
pipeline.clone().resize(800, 600).pipe(firstWritableStream);
pipeline.clone().extract({ left: 20, top: 20, width: 100, height: 100 }).pipe(secondWritableStream);
readableStream.pipe(pipeline);
// firstWritableStream receives auto-rotated, resized readableStream
// secondWritableStream receives auto-rotated, extracted region of readableStream
Returns Sharp
metadata
Fast access to image metadata without decoding any compressed image data.
A Promises/A+ promise is returned when callback
is not provided.
format
: Name of decoder used to decompress image data e.g.jpeg
,png
,webp
,gif
,svg
width
: Number of pixels wideheight
: Number of pixels highspace
: Name of colour space interpretation e.g.srgb
,rgb
,cmyk
,lab
,b-w
...channels
: Number of bands e.g.3
for sRGB,4
for CMYKdensity
: Number of pixels per inch (DPI), if presenthasProfile
: Boolean indicating the presence of an embedded ICC profilehasAlpha
: Boolean indicating the presence of an alpha transparency channelorientation
: Number value of the EXIF Orientation header, if presentexif
: Buffer containing raw EXIF data, if presenticc
: Buffer containing raw ICC profile data, if present
Parameters
callback
[Function] called with the arguments(err, metadata)
Examples
const image = sharp(inputJpg);
image
.metadata()
.then(function(metadata) {
return image
.resize(Math.round(metadata.width / 2))
.webp()
.toBuffer();
})
.then(function(data) {
// data contains a WebP image half the width and height of the original JPEG
});
Returns (Promise<Object> | Sharp)
limitInputPixels
Do not process input images where the number of pixels (width _ height) exceeds this limit. Assumes image dimensions contained in the input metadata can be trusted. The default limit is 268402689 (0x3FFF _ 0x3FFF) pixels.
Parameters
-
limit
(Number | Boolean) an integral Number of pixels, zero or false to remove limit, true to use default limit. -
Throws Error Invalid limit
Returns Sharp
sequentialRead
An advanced setting that switches the libvips access method to VIPS_ACCESS_SEQUENTIAL
.
This will reduce memory usage and can improve performance on some systems.
Parameters
sequentialRead
[Boolean] (optional, defaulttrue
)
Returns Sharp