Metadata
Node BrowserRead and strip image metadata.
meta()
.meta(): Promise<ImageMetadata>.meta(): Promise<ImageMetadata>Read image metadata without processing the image. Returns a Promise directly — do not chain after calling .meta().
Returns
| Field | Type | Description |
|---|---|---|
| width | number | Image width in pixels. |
| height | number | Image height in pixels. |
| format | string | Format: 'jpeg', 'png', 'webp', 'avif', etc. |
| channels | number | Number of channels (3 = RGB, 4 = RGBA). |
| hasAlpha | boolean | Whether the image has an alpha channel. |
| size | number | File size in bytes. |
| exif | Record<string, unknown> | undefined | Parsed EXIF data, if present. |
| icc | Buffer | undefined | Raw ICC color profile, if present. |
Example
const meta = await img('photo.jpg').meta()
console.log(meta.width) // 3840
console.log(meta.height) // 2160
console.log(meta.format) // 'jpeg'
console.log(meta.hasAlpha) // falseconst meta = await img('photo.jpg').meta()
console.log(meta.width) // 3840
console.log(meta.height) // 2160
console.log(meta.format) // 'jpeg'
console.log(meta.hasAlpha) // falsestripMeta()
.stripMeta(): Pipeline.stripMeta(): PipelineRemove all metadata (EXIF, ICC, XMP, IPTC) from the output. Useful for privacy or to reduce file size.
await img('photo.jpg')
.resize(1200)
.stripMeta()
.webp({ quality: 85 })
.toBuffer()await img('photo.jpg')
.resize(1200)
.stripMeta()
.webp({ quality: 85 })
.toBuffer()Stripping metadata typically saves 10–50KB from camera photos, which often embed GPS coordinates, camera model, and thumbnail previews.
Read then process
const meta = await img('photo.jpg').meta()
// Decide processing based on metadata
const pipeline = img('photo.jpg')
if (meta.width > 2000) {
pipeline.resize(1600)
}
const buffer = await pipeline.webp().toBuffer()const meta = await img('photo.jpg').meta()
// Decide processing based on metadata
const pipeline = img('photo.jpg')
if (meta.width > 2000) {
pipeline.resize(1600)
}
const buffer = await pipeline.webp().toBuffer()