Installations
npm install fastimage
Developer Guide
Typescript
Yes
Module System
ESM
Min. Node Version
>= 20.18.0
Node Version
22.12.0
NPM Version
10.9.0
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (98.27%)
JavaScript (1.73%)
Developer
Download Statistics
Total Downloads
222,095
Last Day
19
Last Week
108
Last Month
488
Last Year
21,166
GitHub Statistics
154 Stars
139 Commits
5 Forks
6 Watching
1 Branches
2 Contributors
Package Meta Information
Latest Version
6.0.1
Package Id
fastimage@6.0.1
Unpacked Size
21.53 kB
Size
7.48 kB
File Count
14
NPM Version
10.9.0
Node Version
22.12.0
Publised On
28 Dec 2024
Total Downloads
Cumulative downloads
Total Downloads
222,095
Last day
375%
19
Compared to previous day
Last week
107.7%
108
Compared to previous week
Last month
-19.7%
488
Compared to previous month
Last year
-63.7%
21,166
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
fastimage
A module that finds the size and type of an image by fetching and reading as little data as needed.
http://sw.cowtech.it/fastimage
Installation
Just run:
1npm install fastimage
Usage
The signature is fastimage.info(source, [options], [callback])
.
The source
argument can be:
- String representing a URL (only
http
 andhttps
protocol are supported). - String representing a local file path.
- Buffer containing image data.
- Stream containing image data.
The options
object supports the following options:
threshold
: The maximum about of data (in bytes) to downloaded or read before giving up. Default is4096
.timeout
: The maximum time (in milliseconds) to wait for a URL to be downloaded before giving up. Default isÂ30000
(30 s).userAgent
: The user agent to use when making HTTP(S) requests. Default isfastimage/$VERSION
.
If callback
is not provided, the method returns a Promise
.
Example
1import { info } from 'fastimage' 2 3info('http://fakeimg.pl/1000x1000/', (error, data) => { 4 if (error) { 5 // ... 6 } else { 7 // ... 8 } 9}) 10 11const data = await info('http://fakeimg.pl/1000x1000/')
The callback argument (or the resolved value) will be an object with the following properties:
1{ 2 "width": 1000, // The width of the image in pixels. 3 "height": 1000, // The height of the image in pixels. 4 "type": "png", // The type of the image. Can be one of the supported images formats (see section below). 5 "time": 171.43721 // The time required for the operation, in milliseconds. 6 "analyzed": 979, // The amount of data transferred (in bytes) or read (in case of files or Buffer) to identify the image. 7 "realUrl": "https://fakeimg.pl/1000x1000/", // The final URL of the image after all the redirects. Only present if the source was a URL. 8 "size": 17300, // The size of the image (in bytes). Only present if the source was a URL and if the server returned the "Content-Length" HTTP header. 9}
Streams
Calling fastimage.stream
it will return a Writable stream which will emit the info
event once informations are ready.
The stream accepts only the threshold
option.
1import { stream } from 'fastimage' 2 3const pipe = createReadStream('/path/to/image.png').pipe(stream({ threshold: 100 })) 4 5pipe.on('info', data => { 6 // ... 7})
Supported image formats
The supported image type are (thanks to the image-size module):
- BMP
- CUR
- DDS
- GIF
- ICNS
- ICO
- JPEG
- KTX
- PNG
- PNM (PAM, PBM, PFM, PGM, PPM)
- PSD
- SVG
- TIFF
- WebP
ESM Only
This package only supports to be directly imported in a ESM context.
For informations on how to use it in a CommonJS context, please check this page.
Contributing to fastimage
- Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
- Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
- Fork the project.
- Start a feature/bugfix branch.
- Commit and push until you are happy with your contribution.
- Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
Copyright
Copyright (C) 2015 and above Shogun (shogun@cowtech.it).
Licensed under the MIT license, which can be found at https://choosealicense.com/licenses/isc.
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.md:0
- Info: FSF or OSI recognized license: ISC License: LICENSE.md:0
Reason
7 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 5
Reason
Found 0/30 approved changesets -- 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:9: update your workflow using https://app.stepsecurity.io/secureworkflow/ShogunPanda/fastimage/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:11: update your workflow using https://app.stepsecurity.io/secureworkflow/ShogunPanda/fastimage/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/ShogunPanda/fastimage/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/ShogunPanda/fastimage/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:28: update your workflow using https://app.stepsecurity.io/secureworkflow/ShogunPanda/fastimage/ci.yml/main?enable=pin
- Info: 0 out of 3 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 2 third-party GitHubAction dependencies pinned
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
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 'main'
Score
3.9
/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 fastimage
react-native-fast-image
🚩 FastImage, performant React Native image component.
@d11/react-native-fast-image
🚩 FastImage, performant React Native image component.
storms-fastimage
FastImage, performant React Native image component.
@airintservices/react-native-fast-image
🚩 FastImage, performant React Native image component.