async-image-size

Async image-size, faster and lighter than the original

Usage no npm install needed!

<script type="module">
  import asyncImageSize from 'https://cdn.skypack.dev/async-image-size';
</script>

README

async-image-size

entirely async promise-based image-size

based off typescript and buffers and the like

requires DataView access

Usage

ES2018+

import imageSize from 'async-image-size'
import {promises as fs} from 'fs'
fs.readFile('/path/to/some/file.png').then(imageSize).then(sizes => {
    for (const [width, height, depth = 0] of sizes)
        console.log('file is %d * %d (* %d)', width, height, depth)
})

ES5 (and below)

const imageSize = require('async-image-size').imageSize
const fs = require('fs')
fs.readFile('/path/to/some/file.png', function (err, buf) {
    if (err) throw err
    imageSize(buf).then(function (sizes) {
        for (var i = 0; i < sizes.length; ++i) console.log('file is %d * %d (* %d)', sizes[i][0], sizes[i][1], sizes[i][2])
    })
})

Functions with svg, ico, bmp, icns, tiff, webp, dds, png, jpg, eps, ktx and so on.

Relies heavily on magic numbers for reading information.

Tests

Currently no real tests are existing; only really testing that there aren't errors in the loader rn.

$ npm test
# ........
$ npm run test-esm
[Module] { ....... }