repo
replacements.fyi

// package

is-png

type: "module"

// preferences

// replacements (1)

snippet::is-png-buffer

Simple or drop-in replacement

This package is no longer necessary. You can check the first eight bytes of a buffer against the PNG file signature to detect if it is a PNG image.

// example

function isPng(buf) {
	if (!buf || buf.length < 8) return false;
	return (
		buf[0] === 0x89 &&
		buf[1] === 0x50 &&
		buf[2] === 0x4e &&
		buf[3] === 0x47 &&
		buf[4] === 0x0d &&
		buf[5] === 0x0a &&
		buf[6] === 0x1a &&
		buf[7] === 0x0a
	);
}