# @ayebear/pack

> Simple, multi-threaded texture packer in Go

Latest version **1.2.2** (published 2022-02-26) · MIT license · 0 weekly downloads

## Install

```sh
npm install @ayebear/pack
pnpm add @ayebear/pack
yarn add @ayebear/pack
bun add @ayebear/pack
```

Provides the command `pack`.

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.2 |
| Published | 2022-02-26 |
| First published | 2021-03-19 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | yes |
| Author | Eric Hebert |
| Maintainers | ayebear_ |
| Keywords | golang |

## Links

- npm: https://www.npmjs.com/package/@ayebear/pack
- Repository: https://github.com/ayebear/pack
- Homepage: https://github.com/ayebear/pack#readme
- Issues: https://github.com/ayebear/pack/issues
- npm.io page: https://npm.io/package/@ayebear/pack

## Recent versions

- 1.2.2 (latest) — 2022-02-26
- 1.2.1 — 2022-02-17
- 1.2.0 — 2022-02-17
- 1.1.1 — 2021-04-08
- 1.1.0 — 2021-03-21
- 1.0.7 — 2021-03-20
- 1.0.6 — 2021-03-20
- 1.0.5 — 2021-03-20
- 1.0.4 — 2021-03-19
- 1.0.3 — 2021-03-19
- 1.0.2 — 2021-03-19
- 1.0.1 — 2021-03-19
- 1.0.0 — 2021-03-19

## README

# pack

Simple, multi-threaded texture packer in Go

## Native CLI Usage

### Build

```bash
go build
```

### Run

```bash
./pack -in=images -out=sheets -name=textures
```

For info on more flags, run:

```bash
./pack -h
```

## JS Usage

### Install

#### Yarn

```bash
yarn add --dev @ayebear/pack
```

#### NPM

```bash
npm i -D @ayebear/pack
```

### Run

#### Run with JS wrapper (slower)

```bash
yarn run pack -h
```

#### Run natively (faster)

```bash
./node_modules/@ayebear/pack/pack -h
```

### Client usage

#### Pixi.js v6

##### With static files

Pack outputs a single json file along with (potentially) multiple png files. A pixi.js plugin is included with pack, to load this json file and all associated images in parallel.

```javascript
import { Loader } from '@pixi/loaders'
import { PackSpritesheetLoader } from '@ayebear/pack'

Loader.registerPlugin(PackSpritesheetLoader)
Loader.shared.add('images/textures.json').load(...)
```

##### With bundled files

If you'd like to avoid using static files, and want to "properly" bundle the images and metadata, you can use the `loadSheets` function. The imports for sheetData and sheets might look a bit different depending on your bundler - in this example, parcel v2 is being used:

```javascript
import { Loader } from '@pixi/loaders'
import { loadSheets } from '@ayebear/pack'
import sheetData from 'sheets/textures.json'
import * as sheets from 'sheets/*.png'

// Globbing only gives the "*" part, but we need full path
// to match up with sheetData keys
const images = {}
for (const key in sheets) {
    images[`sheets/${key}.png`] = sheets[key]
}
loadSheets(Loader.shared, sheetData, images).load(...)
```

## About

Pack doesn't do any complicated, slow, puzzle-fitting of sprites. It just bins sprites based on size into separate sprite sheets, in left-to-right grid order. It does this making balanced use of multi-threading to achieve very high performance.

Tested in a real-world project with 300+ sprites. Pack produced 10 sprite sheets in just ~65ms.

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