mirror of
https://github.com/lovell/sharp.git
synced 2025-07-09 10:30:15 +02:00
4.4 KiB
4.4 KiB
metadata
Fast access to (uncached) image metadata without decoding any compressed image data.
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
size
: Total size of image in bytes, for Stream and Buffer input onlywidth
: Number of pixels wide (EXIF orientation is not taken into consideration)height
: Number of pixels high (EXIF orientation is not taken into consideration)space
: Name of colour space interpretation e.g.srgb
,rgb
,cmyk
,lab
,b-w
...channels
: Number of bands e.g.3
for sRGB,4
for CMYKdepth
: Name of pixel depth format e.g.uchar
,char
,ushort
,float
...density
: Number of pixels per inch (DPI), if presentchromaSubsampling
: String containing JPEG chroma subsampling,4:2:0
or4:4:4
for RGB,4:2:0:4
or4:4:4:4
for CMYKisProgressive
: Boolean indicating whether the image is interlaced using a progressive scanpages
: Number of pages/frames contained within the image, with support for TIFF, HEIF, PDF, animated GIF and animated WebPpageHeight
: Number of pixels high each page in a multi-page image will be.loop
: Number of times to loop an animated image, zero refers to a continuous loop.delay
: Delay in ms between each page in an animated image, provided as an array of integers.pagePrimary
: Number of the primary page in a HEIF imagehasProfile
: 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 presentiptc
: Buffer containing raw IPTC data, if presentxmp
: Buffer containing raw XMP data, if presenttifftagPhotoshop
: Buffer containing raw TIFFTAG_PHOTOSHOP 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)
stats
Access to pixel-derived image statistics for every channel in the image.
A Promise
is returned when callback
is not provided.
channels
: Array of channel statistics for each channel in the image. Each channel statistic containsmin
(minimum value in the channel)max
(maximum value in the channel)sum
(sum of all values in a channel)squaresSum
(sum of squared values in a channel)mean
(mean of the values in a channel)stdev
(standard deviation for the values in a channel)minX
(x-coordinate of one of the pixel where the minimum lies)minY
(y-coordinate of one of the pixel where the minimum lies)maxX
(x-coordinate of one of the pixel where the maximum lies)maxY
(y-coordinate of one of the pixel where the maximum lies)
isOpaque
: Is the image fully opaque? Will betrue
if the image has no alpha channel or if every pixel is fully opaque.entropy
: Histogram-based estimation of greyscale entropy, discarding alpha channel if any (experimental)
Parameters
callback
Function? called with the arguments(err, stats)
Examples
const image = sharp(inputJpg);
image
.stats()
.then(function(stats) {
// stats contains the channel-wise statistics array and the isOpaque value
});