Because the program didn’t explicitly specify a format for the data
output, sharp
generated the output in the same format as the image source. In this case the input format was PNG, so your data
buffer content is also in PNG format. That’s why the first 8 bytes of data
are the standard PNG file header, see https://en.wikipedia.org/wiki/Portable_Network_Graphics#File_header
To get the data
output formatted as a collection of pixels, regardless of whatever the image source’s format might have been, replace
.toBuffer({resolveWithObject: true})
with
.raw()
.toBuffer({resolveWithObject: true})
solved Javascript how to get pixel colour from image data