# ktx2-encoder

> KTX2(.ktx2) encoder for browser applications

Latest version **0.6.0** (published 2026-07-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install ktx2-encoder
pnpm add ktx2-encoder
yarn add ktx2-encoder
bun add ktx2-encoder
```

## Health

**Score 65/100 (B)** — status: active.

Positive: esm support; no vulnerabilities; has provenance; recently updated; high maintenance score.

Warnings: low downloads; no types; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.6.0 |
| Published | 2026-07-19 |
| First published | 2023-02-22 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM |
| Dependencies | 1 |
| Unpacked size | 3.3 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 37 |
| Author | Hu Song |
| Maintainers | husong |
| Keywords | ktx, ktx2, basis, texture, encoder, webgl, webgpu |

## Links

- npm: https://www.npmjs.com/package/ktx2-encoder
- Repository: https://github.com/gz65555/ktx2-encoder
- Homepage: https://github.com/gz65555/ktx2-encoder#readme
- Issues: https://github.com/gz65555/ktx2-encoder/issues
- npm.io page: https://npm.io/package/ktx2-encoder

## Dependencies (1)

- [ktx-parse](https://npm.io/package/ktx-parse.md) ^1.1.0

## Alternatives

- [flatbuffers](https://npm.io/package/flatbuffers.md) — 6.0M weekly downloads
- [jwt-simple](https://npm.io/package/jwt-simple.md) — 259.5K weekly downloads
- [@exodus/patch-broken-hermes-typed-arrays](https://npm.io/package/@exodus/patch-broken-hermes-typed-arrays.md) — 28.5K weekly downloads
- [@native-to-anchor/buffer-layout](https://npm.io/package/@native-to-anchor/buffer-layout.md) — 12.2K weekly downloads
- [binary-parser-encoder](https://npm.io/package/binary-parser-encoder.md) — 5.3K weekly downloads

## Recent versions

- 0.6.0 (latest) — 2026-07-19
- 0.5.4 — 2026-07-18
- 0.5.3 — 2026-04-29
- 0.5.1 — 2025-10-27
- 0.5.0 — 2025-09-15
- 0.4.2 — 2025-04-20
- 0.4.1 — 2025-03-28
- 0.4.0 — 2025-03-27
- 0.3.0 — 2025-01-17
- 0.2.0 — 2024-12-10
- 0.1.1 — 2024-11-28
- 0.1.0 — 2024-07-03
- 0.0.0-experimental.5 — 2024-03-19
- 0.0.0-experimental.4 — 2024-03-19
- 0.0.0-experimental.3 — 2024-03-19
- … 8 more at https://npm.io/package/ktx2-encoder/versions

## README

# ktx2-encoder

[![Latest NPM release](https://img.shields.io/npm/v/ktx2-encoder.svg)](https://www.npmjs.com/package/ktx2-encoder) [![License](https://img.shields.io/badge/license-MIT-007ec6.svg)](https://github.com/gz65555/ktx2-encoder)

A lightweight JavaScript library for converting images to KTX2 (.ktx2) format. Powered by [BinomialLLC/basis_universal](https://github.com/BinomialLLC/basis_universal).

## Features

- Convert images to KTX2 format
- Support for both 2D images and cubemaps
- Integration with gltf-transform
- Support both Browser and Node.js

## Quick Start

Install:

```shell
npm install --save ktx2-encoder
```

Import and encode an image:

```javascript
import { encodeToKTX2 } from "ktx2-encoder";

const source = new Uint8Array(await file.arrayBuffer());
const ktx2Data = await encodeToKTX2(source, {
  isUASTC: true,
  generateMipmap: true
});
```

In browsers, `encodeToKTX2` also accepts exactly six `Uint8Array` images to encode a cubemap, ordered as `[posx, negx, posy, negy, posz, negz]`.

See the [API guide](./website/guide/api.md) for more details.

## For gltf-transform

For users of [glTF Transform](https://gltf-transform.dev/), use the provided `ktx2` transform. In Node.js, pass an `imageDecoder`; browser builds provide one automatically.

```typescript
import { ktx2 } from "ktx2-encoder/gltf-transform";
import sharp from "sharp";

const imageDecoder = async (buffer: Uint8Array) => {
  const { data, info } = await sharp(buffer).ensureAlpha().raw().toBuffer({ resolveWithObject: true });
  return { data: new Uint8Array(data), width: info.width, height: info.height };
};

await document.transform(
  ktx2({
    isUASTC: true,
    enableDebug: false,
    generateMipmap: true,
    imageDecoder
  })
);
```

The browser build loads its bundled, version-matched `basis_encoder.wasm` automatically, with no CDN fallback. To serve a matching WASM file from a custom location, set `wasmUrl` explicitly. See the [advanced guide](./website/guide/advanced.md#custom-wasm-loading).

## Tool

Open the page of [ktx2 encoder tool](https://husong.me/ktx2-encoder/tools), you can use it to encode your image to ktx2.

---
_Source: https://npm.io/package/ktx2-encoder · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
