Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
probe-image-size
Advanced tools
Changelog
[7.2.3] - 2022-01-27
Error
extend in FF, #71.Readme
Get image size without full download. Supported image types: JPG, GIF, PNG, WebP, BMP, TIFF, SVG, PSD, ICO, AVIF, HEIC, HEIF.
Key features:
npm install probe-image-size
const probe = require('probe-image-size');
// Get by URL
let result = await probe('http://example.com/image.jpg');
console.log(result); // =>
/*
{
width: xx,
height: yy,
type: 'jpg',
mime: 'image/jpeg',
wUnits: 'px',
hUnits: 'px',
url: 'http://example.com/image.jpg'
}
*/
// By URL with options
let result = await probe('http://example.com/image.jpg', { rejectUnauthorized: false });
console.log(result);
// From the stream
let result = await probe(require('fs').createReadStream('image.jpg'));
console.log(result);
// From a Buffer (sync)
let data = require('fs').readFileSync('image.jpg');
console.log(probe.sync(data));
Note:
stream.js
/ http.js
/ sync.js
directly.http.js
dependencies, you can create your own wrapper
for stream.js
.src
can be of this types:
options
- HTTP only. See needle
documentation, and customized defaults.keepOpen
(Boolean) - stream only. Keep stream open after parser finishes
(input stream will be closed by default)result
(Promise) contains:
{
width: XX,
height: YY,
length: ZZ, // byte length of the file (if available, HTTP only)
type: ..., // image 'type' (usual file name extention)
mime: ..., // mime type
wUnits: 'px', // width units type ('px' by default, can be different for SVG)
hUnits: 'px', // height units type ('px' by default, can be different for SVG)
url: ..., // HTTP only, last url for the image in chain of redirects
// (if no redirects, same as src)
// optional, image orientation (from Exif), number from 1 to 8;
// you may wish to swap width and height if orientation is >= 5
orientation: X,
// optional, full list of sizes for ICO (always) and AVIF (if multiple images)
variants: [ { width, height }, ... ] | undefined
}
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 to ECONTENT
if the library failed to parse the file;status
- equals to a HTTP status code if it receives a non-200 response.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.
You can support this project via Tidelift subscription.
FAQs
Get image size without full download (JPG, GIF, PNG, WebP, BMP, TIFF, PSD)
The npm package probe-image-size receives a total of 484,605 weekly downloads. As such, probe-image-size popularity was classified as popular.
We found that probe-image-size demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.