image-size-from-url
v2.0.0
Published
Get image dimensions (width & height) from a URL. Supports JPEG, PNG, GIF, WebP, SVG, ICO, BMP, PSD, CUR, DDS.
Downloads
436
Maintainers
Readme
image-size-from-url
Get image dimensions (width & height) from a URL. No need to download the full image — just pass a URL and get back the size.
Install
npm i image-size-from-urlUsage
import getImageSize from 'image-size-from-url';
// Regular image → { width, height }
const { width, height } = await getImageSize('https://example.com/photo.jpg');
// ICO/CUR → { images: [{ width, height }, ...] }
const { images } = await getImageSize('https://example.com/favicon.ico');Error handling
try {
const { width, height } = await getImageSize('https://example.com/photo.png');
} catch (e) {
// Throws if: URL is not http/https, format is unsupported,
// request times out (10s), or file exceeds 10 MB
}Supported formats
| Format | Extension |
|--------|-----------|
| JPEG | .jpg |
| PNG | .png |
| GIF | .gif |
| WebP | .webp |
| SVG | .svg |
| ICO | .ico |
| BMP | .bmp |
| PSD | .psd |
| CUR | .cur |
| DDS | .dds |
Notes
- Only
http://andhttps://URLs are accepted - Request timeout: 10 seconds
- Max file size: 10 MB
