Metadata

Node Browser

Read 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

FieldTypeDescription
widthnumberImage width in pixels.
heightnumberImage height in pixels.
formatstringFormat: 'jpeg', 'png', 'webp', 'avif', etc.
channelsnumberNumber of channels (3 = RGB, 4 = RGBA).
hasAlphabooleanWhether the image has an alpha channel.
sizenumberFile size in bytes.
exifRecord<string, unknown> | undefinedParsed EXIF data, if present.
iccBuffer | undefinedRaw 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) // false
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) // false

stripMeta()

.stripMeta(): Pipeline
.stripMeta(): Pipeline

Remove 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()