You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

readme.md 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. # is-png [![Build Status](https://travis-ci.org/sindresorhus/is-png.svg?branch=master)](https://travis-ci.org/sindresorhus/is-png)
  2. > Check if a Buffer/Uint8Array is a [PNG](https://en.wikipedia.org/wiki/Portable_Network_Graphics) image
  3. ## Install
  4. ```
  5. $ npm install is-png
  6. ```
  7. ## Usage
  8. ##### Node.js
  9. ```js
  10. const readChunk = require('read-chunk'); // npm install read-chunk
  11. const isPng = require('is-png');
  12. const buffer = readChunk.sync('unicorn.png', 0, 8);
  13. isPng(buffer);
  14. //=> true
  15. ```
  16. ##### Browser
  17. ```js
  18. (async () => {
  19. const response = await fetch('unicorn.png');
  20. const buffer = await response.arrayBuffer();
  21. isPng(new Uint8Array(buffer));
  22. //=> true
  23. })();
  24. ```
  25. ## API
  26. ### isPng(buffer)
  27. Accepts a Buffer (Node.js) or Uint8Array. Returns a `boolean` of whether `buffer` is a PNG image.
  28. #### buffer
  29. The buffer to check. It only needs the first 8 bytes.
  30. ## Related
  31. - [file-type](https://github.com/sindresorhus/file-type) - Detect the file type of a Buffer/Uint8Array/ArrayBuffer
  32. ## License
  33. MIT © [Sindre Sorhus](https://sindresorhus.com)