CoolFace
Apppublic

TrinetraLabs/Placebo_AI

sourceHugging Faceupdated 2mo agoView on Hugging Face
0likes
Readme.md185 linesDownload Raw Back to image-size
1# image-size2 3[![Build Status](https://circleci.com/gh/image-size/image-size.svg?style=shield)](https://circleci.com/gh/image-size/image-size)4[![Package Version](https://img.shields.io/npm/v/image-size.svg)](https://www.npmjs.com/package/image-size)5[![Downloads](https://img.shields.io/npm/dm/image-size.svg)](http://npm-stat.com/charts.html?package=image-size&author=&from=&to=)6 7A [Node](https://nodejs.org/en/) module to get dimensions of any image file8 9## Supported formats10 11- BMP12- CUR13- DDS14- GIF15- HEIC (HEIF, AVCI, AVIF)16- ICNS17- ICO18- J2C19- JPEG-2000 (JP2)20- JPEG21- JPEG-XL22- KTX (1 and 2)23- PNG24- PNM (PAM, PBM, PFM, PGM, PPM)25- PSD26- SVG27- TGA28- TIFF29- WebP30 31## Programmatic Usage32 33```shell34npm install image-size --save35```36 37or38 39```shell40yarn add image-size41```42 43### Synchronous44 45```javascript46const sizeOf = require("image-size")47const dimensions = sizeOf("images/funny-cats.png")48console.log(dimensions.width, dimensions.height)49```50 51### Asynchronous52 53```javascript54const sizeOf = require("image-size")55sizeOf("images/funny-cats.png", function (err, dimensions) {56  console.log(dimensions.width, dimensions.height)57})58```59 60NOTE: The asynchronous version doesn't work if the input is a Buffer. Use synchronous version instead.61 62Also, the asynchronous functions have a default concurrency limit of **100**63To change this limit, you can call the `setConcurrency` function like this:64 65```javascript66const sizeOf = require("image-size")67sizeOf.setConcurrency(123456)68```69 70### Using promises (nodejs 10.x+)71 72```javascript73const { promisify } = require("util")74const sizeOf = promisify(require("image-size"))75sizeOf("images/funny-cats.png")76  .then((dimensions) => {77    console.log(dimensions.width, dimensions.height)78  })79  .catch((err) => console.error(err))80```81 82### Async/Await (Typescript & ES7)83 84```javascript85const { promisify } = require("util")86const sizeOf = promisify(require("image-size"))(async () => {87  try {88    const dimensions = await sizeOf("images/funny-cats.png")89    console.log(dimensions.width, dimensions.height)90  } catch (err) {91    console.error(err)92  }93})().then((c) => console.log(c))94```95 96### Multi-size97 98If the target file is an icon (.ico) or a cursor (.cur), the `width` and `height` will be the ones of the first found image.99 100An additional `images` array is available and returns the dimensions of all the available images101 102```javascript103const sizeOf = require("image-size")104const images = sizeOf("images/multi-size.ico").images105for (const dimensions of images) {106  console.log(dimensions.width, dimensions.height)107}108```109 110### Using a URL111 112```javascript113const url = require("url")114const http = require("http")115 116const sizeOf = require("image-size")117 118const imgUrl = "http://my-amazing-website.com/image.jpeg"119const options = url.parse(imgUrl)120 121http.get(options, function (response) {122  const chunks = []123  response124    .on("data", function (chunk) {125      chunks.push(chunk)126    })127    .on("end", function () {128      const buffer = Buffer.concat(chunks)129      console.log(sizeOf(buffer))130    })131})132```133 134You can optionally check the buffer lengths & stop downloading the image after a few kilobytes.135**You don't need to download the entire image**136 137### Disabling certain image types138 139```javascript140const imageSize = require("image-size")141imageSize.disableTypes(["tiff", "ico"])142```143 144### Disabling all file-system reads145 146```javascript147const imageSize = require("image-size")148imageSize.disableFS(true)149```150 151### JPEG image orientation152 153If 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](https://exiftool.org/TagNames/EXIF.html#:~:text=0x0112,8%20=%20Rotate%20270%20CW) representing a type of orientation.154 155```javascript156const sizeOf = require("image-size")157const dimensions = sizeOf("images/photo.jpeg")158console.log(dimensions.orientation)159```160 161## Command-Line Usage (CLI)162 163```shell164npm install image-size --global165```166 167or168 169```shell170yarn global add image-size171```172 173followed by174 175```shell176image-size image1 [image2] [image3] ...177```178 179## Credits180 181not a direct port, but an attempt to have something like182[dabble's imagesize](https://github.com/dabble/imagesize/blob/master/lib/image_size.rb) as a node module.183 184## [Contributors](Contributors.md)185