Galerie und tage
This commit is contained in:
40
node_modules/is-png/readme.md
generated
vendored
40
node_modules/is-png/readme.md
generated
vendored
@@ -1,12 +1,14 @@
|
||||
# is-png [](https://travis-ci.org/sindresorhus/is-png)
|
||||
|
||||
> Check if a Buffer/Uint8Array is a [PNG](https://en.wikipedia.org/wiki/Portable_Network_Graphics) image
|
||||
> Check if a Buffer/Uint8Array is a [PNG](http://en.wikipedia.org/wiki/Portable_Network_Graphics) image
|
||||
|
||||
Used by [image-type](https://github.com/sindresorhus/image-type).
|
||||
|
||||
|
||||
## Install
|
||||
|
||||
```
|
||||
$ npm install is-png
|
||||
```sh
|
||||
$ npm install --save is-png
|
||||
```
|
||||
|
||||
|
||||
@@ -15,9 +17,9 @@ $ npm install is-png
|
||||
##### Node.js
|
||||
|
||||
```js
|
||||
const readChunk = require('read-chunk'); // npm install read-chunk
|
||||
const isPng = require('is-png');
|
||||
const buffer = readChunk.sync('unicorn.png', 0, 8);
|
||||
var readChunk = require('read-chunk'); // npm install read-chunk
|
||||
var isPng = require('is-png');
|
||||
var buffer = readChunk.sync('unicorn.png', 0, 8);
|
||||
|
||||
isPng(buffer);
|
||||
//=> true
|
||||
@@ -26,13 +28,16 @@ isPng(buffer);
|
||||
##### Browser
|
||||
|
||||
```js
|
||||
(async () => {
|
||||
const response = await fetch('unicorn.png');
|
||||
const buffer = await response.arrayBuffer();
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open('GET', 'unicorn.png');
|
||||
xhr.responseType = 'arraybuffer';
|
||||
|
||||
isPng(new Uint8Array(buffer));
|
||||
xhr.onload = function () {
|
||||
isPng(new Uint8Array(this.response));
|
||||
//=> true
|
||||
})();
|
||||
};
|
||||
|
||||
xhr.send();
|
||||
```
|
||||
|
||||
|
||||
@@ -40,18 +45,11 @@ isPng(buffer);
|
||||
|
||||
### isPng(buffer)
|
||||
|
||||
Accepts a Buffer (Node.js) or Uint8Array. Returns a `boolean` of whether `buffer` is a PNG image.
|
||||
Accepts a Buffer (Node.js) or Uint8Array.
|
||||
|
||||
#### buffer
|
||||
|
||||
The buffer to check. It only needs the first 8 bytes.
|
||||
|
||||
|
||||
## Related
|
||||
|
||||
- [file-type](https://github.com/sindresorhus/file-type) - Detect the file type of a Buffer/Uint8Array/ArrayBuffer
|
||||
It only needs the first 8 bytes.
|
||||
|
||||
|
||||
## License
|
||||
|
||||
MIT © [Sindre Sorhus](https://sindresorhus.com)
|
||||
MIT © [Sindre Sorhus](http://sindresorhus.com)
|
||||
|
||||
Reference in New Issue
Block a user