https://github.com/tonybart1337/image-size-stream
Get image dimensions from stream
https://github.com/tonybart1337/image-size-stream
buffer dimensions images stream
Last synced: 6 months ago
JSON representation
Get image dimensions from stream
- Host: GitHub
- URL: https://github.com/tonybart1337/image-size-stream
- Owner: tonybart1337
- License: mit
- Created: 2018-07-06T23:51:16.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2022-07-14T12:21:03.000Z (almost 4 years ago)
- Last Synced: 2024-08-08T20:56:39.382Z (almost 2 years ago)
- Topics: buffer, dimensions, images, stream
- Language: JavaScript
- Size: 2.18 MB
- Stars: 4
- Watchers: 2
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# image-dimensions-stream
A [Node](https://nodejs.org/en/) module to get dimensions of any image file stream
## Supported formats
* BMP
* GIF
* JPEG
* PNG
* PSD
* DDS
* WebP
### Upcoming
* SWF
* CUR
* ICO
* ICNS
* TIFF
* SVG
## Programmatic Usage
```
yarn add image-dimensions-stream
```
### Example
```javascript
const ImageDimensionsStream = require('image-dimensions-stream');
const pipeline = util.promisify(require('stream').pipeline);
async function main() {
const sizeStream = new ImageDimensionsStream();
let result = {
mime: null,
dimensions: null,
};
sizeStream.on('mime', (mime) => {
console.log('mime:', mime);
result.mime = mime;
});
sizeStream.on('dimensions', (dimensions) => {
console.log('dimensions:', dimensions);
result.dimensions = dimensions;
});
await pipeline(fs.createReadStream('images/funny-cats.png'), sizeStream, fs.createWriteStream('/dev/null'));
return result;
}
main().then(console.log).catch(console.error);
```
## Options
Key | Type | Default | Description
--- | --- | --- | ---
`requireMime` | `boolean` `function` | `true` | destroy stream if mime can't be found
`requireDimensions` | `boolean` `function` | `true` | destroy stream if dimensions can't be found
`exif` | `boolean` `function` | `false` | use EXIF (Orientation) data if available
`requireValidExif` | `boolean` `function` | `false` | destroy stream on invalid EXIF data otherwise just skip EXIF block. Only useful if `exif` option returns true
`maxMimeChunkOffset` | `number` | Minimum value possible | Whether to destroy the stream if we couldn't detect mime type after reading this amount of bytes
`maxMimeBufferSize` | `number` in bytes | 4100 | Maximum buffer size when detecting mime type
`maxDimensionsBufferSize` | `number` in bytes | 64000 | Maximum buffer size when detecting dimensions
## Credits
[image-size](https://github.com/image-size/image-size) for test images and file structures