Get image size without full download. Supported image types: JPG, GIF, PNG, WebP, BMP, TIFF, SVG, PSD, ICO.
Installations
npm install probe-image-size
Developer Guide
Typescript
No
Module System
N/A
Node Version
16.13.0
NPM Version
8.1.0
Score
57.7
Supply Chain
98.7
Quality
75.4
Maintenance
100
Vulnerability
99.3
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
nodeca
Download Statistics
Total Downloads
150,759,051
Last Day
42,199
Last Week
265,396
Last Month
2,038,712
Last Year
30,545,937
GitHub Statistics
991 Stars
184 Commits
77 Forks
14 Watching
2 Branches
11 Contributors
Bundle Size
342.59 kB
Minified
179.74 kB
Minified + Gzipped
Package Meta Information
Latest Version
7.2.3
Package Id
probe-image-size@7.2.3
Unpacked Size
68.64 kB
Size
16.97 kB
File Count
32
NPM Version
8.1.0
Node Version
16.13.0
Total Downloads
Cumulative downloads
Total Downloads
150,759,051
Last day
-9.3%
42,199
Compared to previous day
Last week
-40%
265,396
Compared to previous week
Last month
-13.2%
2,038,712
Compared to previous month
Last year
-4.2%
30,545,937
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
3
probe-image-size
Get image size without full download. Supported image types: JPG, GIF, PNG, WebP, BMP, TIFF, SVG, PSD, ICO, AVIF, HEIC, HEIF.
Key features:
- small size, no heavy dependencies
- works with remote and local data
- effective with big images (speed/memory), download minimal data from remotes
- extracts orientation value when available
- easy to browserify (splitted to components)
Install
1npm install probe-image-size
Example
1const probe = require('probe-image-size'); 2 3// Get by URL 4let result = await probe('http://example.com/image.jpg'); 5console.log(result); // => 6/* 7 { 8 width: xx, 9 height: yy, 10 type: 'jpg', 11 mime: 'image/jpeg', 12 wUnits: 'px', 13 hUnits: 'px', 14 url: 'http://example.com/image.jpg' 15 } 16*/ 17 18 19// By URL with options 20let result = await probe('http://example.com/image.jpg', { rejectUnauthorized: false }); 21console.log(result); 22 23 24// From the stream 25let result = await probe(require('fs').createReadStream('image.jpg')); 26console.log(result); 27 28 29// From a Buffer (sync) 30let data = require('fs').readFileSync('image.jpg'); 31console.log(probe.sync(data));
API
Note:
- You can access/browserify
stream.js
/http.js
/sync.js
directly. - If you don't like
http.js
dependencies, you can create your own wrapper forstream.js
.
probe(src [, options|keepOpen]) -> Promise
src
can be of this types:- String - URL to fetch
- Stream - readable stream
options
- HTTP only. Seeneedle
documentation, and customized defaults.keepOpen
(Boolean) - stream only. Keep stream open after parser finishes (input stream will be closed by default)
result
(Promise) contains:
1{ 2 width: XX, 3 height: YY, 4 length: ZZ, // byte length of the file (if available, HTTP only) 5 type: ..., // image 'type' (usual file name extention) 6 mime: ..., // mime type 7 wUnits: 'px', // width units type ('px' by default, can be different for SVG) 8 hUnits: 'px', // height units type ('px' by default, can be different for SVG) 9 url: ..., // HTTP only, last url for the image in chain of redirects 10 // (if no redirects, same as src) 11 12 // optional, image orientation (from Exif), number from 1 to 8; 13 // you may wish to swap width and height if orientation is >= 5 14 orientation: X, 15 16 // optional, full list of sizes for ICO (always) and AVIF (if multiple images) 17 variants: [ { width, height }, ... ] | undefined 18}
Width and height in the output object represent image size before any transformations (orientation, cropping) are applied. Orientation is returned separately, which you may wish to apply afterwards depending on browser support (browsers only support JPEG orientation for now). See known issues for details.
Returned errors can be extended with 2 fields:
code
- equals toECONTENT
if the library failed to parse the file;status
- equals to a HTTP status code if it receives a non-200 response.
probe.sync(src) -> result|null
Sync version can eat arrays, typed arrays and buffers. On success it returns the same result as async version. On fail it returns null.
Note. Formats like JPEG & TIFF can store size anywhere (far from the head). That usually does not happens, but if you need guarantees - always provide full file content to sync methods. We strongly recommend to use async version as memory-friendly.
Similar projects
Support probe-image-size
You can support this project via Tidelift subscription.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
security policy file detected
Details
- Info: security policy file detected: github.com/nodeca/.github/SECURITY.md:1
- Info: Found linked content: github.com/nodeca/.github/SECURITY.md:1
- Info: Found disclosure, vulnerability, and/or timelines in security policy: github.com/nodeca/.github/SECURITY.md:1
- Info: Found text in security policy: github.com/nodeca/.github/SECURITY.md:1
Reason
Found 3/28 approved changesets -- score normalized to 1
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:19: update your workflow using https://app.stepsecurity.io/secureworkflow/nodeca/probe-image-size/ci.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:22: update your workflow using https://app.stepsecurity.io/secureworkflow/nodeca/probe-image-size/ci.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:36: update your workflow using https://app.stepsecurity.io/secureworkflow/nodeca/probe-image-size/ci.yml/master?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/ci.yml:28
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 5 are checked with a SAST tool
Score
4.2
/10
Last Scanned on 2024-12-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to probe-image-size
@types/probe-image-size
TypeScript definitions for probe-image-size
hexo-filter-probe-image-size
Probe and set image sizes in hexo web pages
co-probe-image-size
co version of probe-image-size, fix read large image error problem
probe-image-size-loader
Uses probe-image-size to inject the height and width into image imports.