npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@konsumer/image

v0.0.9

Published

Use the minimum amount of data to get info about an image

Downloads

15

Readme

image

Use the minimum amount of data to get info about an image.

These image-types are supported:

  • BMP
  • CUR
  • DDS
  • GIF
  • ICNS
  • ICO
  • J2C
  • JP2
  • JPEG
  • KTX
  • PNG
  • PNM (PAM, PBM, PFM, PGM, PPM)
  • PSD
  • SVG
  • TGA
  • TIFF
  • WebP

Features

  • You are not locked into nodejs or the browser or anything. This can be used in many environments (node, browser, deno, bun, Cloudflare workers, etc.)
  • Grabs the smallest amount of bytes from an image as possible, and get the most info possible. This means it's fast, light, and doesn't take a lot of RAM. 1 byte is enough to basically detect format. 20 bytes is enough to get height/width, color information, and more, for most image formats.
  • No external dependencies. Just add the single file to your project and use it.
  • Published as ESM and CommonJS module for easy use, everywhere.
  • It works with all kinds of things, like Buffer, ArrayBuffer, Uint8Array, or any array of unsigned integers (representing bytes.)
  • Use it with fetch or your favorite HTTP library.

Installation

nodejs / build-system

npm i @konsumer/image

Usage

There are 3 exported functions:

  • info(bytes) - synchronous, use bytes to get as much info as possible. Here is a server-side example that uses it, but it also works in the browser.
  • infoFetch(url) - asynchronous, calls fetch to download very little data, and gets info. Here is a server-side demo, and here is browser-demo.
  • infoFetchNoCors(url) - asynchronous, Similar to infoFetch, but only for browser. It will get less info, and only supports images that your browser supports, but it can get height/width even when CORS would stop you. Here is an example usage.

Note: You only really need info(url), and it's the default export, because it detects a URL (string param) and will try to call infoFetch(url) / infoFetchNoCors(url).

current nodejs / bun

import imagemeta from '@konsumer/image'
console.log(await imagemeta('https://placekitten.com/200/200'))

You can see a demo here.

deno

import imagemeta from 'npm:@konsumer/image'
console.log(await imagemeta('https://placekitten.com/200/200'))

older nodejs

const imagemeta = require('@konsumer/image')

// if your node doesn't have fetch
global.fetch = require('node-fetch')

imagemeta('https://placekitten.com/200/200')
  .then(console.log)

browser-only

<script type=module>
import imagemeta from 'https://cdn.skypack.dev/@konsumer/image'
console.log(await imagemeta('https://placekitten.com/200/200'))
</script>

You can see a demo here.

TODO

  • I need to clean up & normalize the data, and get more info about every format.
  • Make a top-level DataView and use it for everything (similar to Buffer, no buffer utils needed.) See jpeg for example.
  • Also get mime, url, and filesize (on URLS)

Thanks

  • I got a lot of the image byte-parsing stuff from image-size
  • jpeg-header seemed to be the most reliable JPEG parsing I have found, in JS.