Gathering detailed insights and metrics for tea-image-size
Gathering detailed insights and metrics for tea-image-size
npm install tea-image-size
Typescript
Module System
Min. Node Version
Node Version
NPM Version
65.4
Supply Chain
97.9
Quality
75.6
Maintenance
100
Vulnerability
100
License
TypeScript (97.32%)
JavaScript (2.68%)
Total Downloads
5,179
Last Day
1
Last Week
2
Last Month
6
Last Year
5,179
498 Commits
1 Branches
1 Contributors
Latest Version
1.1.1
Package Id
tea-image-size@1.1.1
Unpacked Size
7.85 kB
Size
3.38 kB
File Count
4
NPM Version
9.6.4
Node Version
20.1.0
Publised On
27 Mar 2024
Cumulative downloads
Total Downloads
Last day
0%
1
Compared to previous day
Last week
100%
2
Compared to previous week
Last month
-82.9%
6
Compared to previous month
Last year
0%
5,179
Compared to previous year
A Node module to get dimensions of any image file
1npm install image-size --save
or
1yarn add image-size
1const sizeOf = require("image-size") 2const dimensions = sizeOf("images/funny-cats.png") 3console.log(dimensions.width, dimensions.height)
1const sizeOf = require("image-size") 2sizeOf("images/funny-cats.png", function (err, dimensions) { 3 console.log(dimensions.width, dimensions.height) 4})
NOTE: The asynchronous version doesn't work if the input is a Buffer. Use synchronous version instead.
Also, the asynchronous functions have a default concurrency limit of 100
To change this limit, you can call the setConcurrency
function like this:
1const sizeOf = require("image-size") 2sizeOf.setConcurrency(123456)
1const { promisify } = require("util") 2const sizeOf = promisify(require("image-size")) 3sizeOf("images/funny-cats.png") 4 .then((dimensions) => { 5 console.log(dimensions.width, dimensions.height) 6 }) 7 .catch((err) => console.error(err))
1const { promisify } = require("util") 2const sizeOf = promisify(require("image-size"))(async () => { 3 try { 4 const dimensions = await sizeOf("images/funny-cats.png") 5 console.log(dimensions.width, dimensions.height) 6 } catch (err) { 7 console.error(err) 8 } 9})().then((c) => console.log(c))
If the target file is an icon (.ico) or a cursor (.cur), the width
and height
will be the ones of the first found image.
An additional images
array is available and returns the dimensions of all the available images
1const sizeOf = require("image-size") 2const images = sizeOf("images/multi-size.ico").images 3for (const dimensions of images) { 4 console.log(dimensions.width, dimensions.height) 5}
1const url = require("url") 2const http = require("http") 3 4const sizeOf = require("image-size") 5 6const imgUrl = "http://my-amazing-website.com/image.jpeg" 7const options = url.parse(imgUrl) 8 9http.get(options, function (response) { 10 const chunks = [] 11 response 12 .on("data", function (chunk) { 13 chunks.push(chunk) 14 }) 15 .on("end", function () { 16 const buffer = Buffer.concat(chunks) 17 console.log(sizeOf(buffer)) 18 }) 19})
You can optionally check the buffer lengths & stop downloading the image after a few kilobytes. You don't need to download the entire image
1const imageSize = require("image-size") 2imageSize.disableTypes(["tiff", "ico"])
1const imageSize = require("image-size") 2imageSize.disableFS(true)
If the orientation is present in the JPEG EXIF metadata, it will be returned by the function. The orientation value is a number between 1 and 8 representing a type of orientation.
1const sizeOf = require("image-size") 2const dimensions = sizeOf("images/photo.jpeg") 3console.log(dimensions.orientation)
1npm install image-size --global
or
1yarn global add image-size
followed by
1image-size image1 [image2] [image3] ...
not a direct port, but an attempt to have something like dabble's imagesize as a node module.
No vulnerabilities found.
No security vulnerabilities found.