JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1208
  • Score
    100M100P100Q115804F
  • License (CC0-1.0 AND Apache-2.0 AND BSD-3-Clause)

Codecs for NodeJS

Package Exports

  • @astropub/codecs
  • @astropub/codecs/avif
  • @astropub/codecs/jpg
  • @astropub/codecs/jxl
  • @astropub/codecs/png
  • @astropub/codecs/resize
  • @astropub/codecs/webp
  • @astropub/codecs/wp2

Readme

Codecs

Codecs lets you use read, write, and edit different image formats.

npm install @astropub/codecs

Usage

import * as fs from 'node:fs/promises'
import * as codecs from '@astropub/codecs'

// decode the JPG image
const image = await codecs.load(
  await fs.readFile(
    './kitten.jpg'
  )
)

image.data // Uint8ClampedArray of the decoded JPG
image.width // Width of the decoded JPG
image.height // Height of the decoded JPG

// encode as Avif/WebP, at 320, 640, 960
const encodes = await image.encode({
        sizes: [ 320, 640, 960 ],
        types: [ 'image/avif', 'image/webp' ],
})

// save various sizes and encodings
await Promise.all(
  encodes.map(encoding => encoding.then(
    encoded => fs.writeFile(
      `./kitten-${encoded.width}.${encoded.extension}`,
      encoded.data
    )
  ))
)

Individual exports are also available.

import * as avif from '@astropub/codecs/avif'
import * as jpg from '@astropub/codecs/jpg'
import * as jxl from '@astropub/codecs/jxl'
import * as png from '@astropub/codecs/png'
import * as webp from '@astropub/codecs/webp'
import * as wp2 from '@astropub/codecs/wp2'
import { resize } from '@astropub/codecs/resize'

License

Codecs is a remix of Squoosh!.

Code original to this project is licensed under the CC0-1.0 License.

Code from Squoosh! is licensed under the Apache-2.0 License, Copyright Google Inc.

Code from Avif Encoder is licensed under the BSD License (BSD), Copyright Joe Drago.

Code from MozJPEG is licensed under the Modified (3-clause) BSD License (BSD), Copyright Viktor Szathmáry.

Code from JXL is licensed under the Apache-2.0 License, Copyright Google Inc.

Code from OxiPNG is licensed under the MIT License (MIT), Copyright Joshua Holmer.

Code from WebP is licensed under the Modified (3-clause) BSD License (BSD), Copyright Google Inc.

Code from WebP2 is licensed under the Apache-2.0 License, Copyright Google Inc.