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

texturepack

v0.1.2

Published

Utility for packing a folder of images to an atlas texture

Downloads

1

Readme

version node code style: prettier

Setup

  • Install Node.js
  • Navigate to your project root and run:
$ npm install texturepack
  • Or install globally from anywhere:
$ npm install texturepack -g

This package uses sharp to manipulate images, which downloads its own binaries on install, so it does not need any external binary like ImageMagick.

Usage

texturepack images-folder

Takes all images in specified folder images-folder and outputs two files:

  • atlas.png
  • atlas.json

Which is a standard texture atlas format. The specification was tested to work with Phaser.

It can also be used programmatically:

const { texturepack } = require("texturepack");

texturepack({
	folder: "images",
	prettify: true,
	packOptions: {
		maxWidth: 2048,
		maxHeight: 2048
	}
})
	.then(() => console.log("Pack successful"))
	.catch(console.error);

It returns a promise which resolves when packing is completed, or rejects if an error occurred.

When all textures cannot fit in a single image, it will throw an error.

Animations

It's also able to create animations from single images. It works using a naming convention: a filename like explosion-sprite5x4.png would by cut in 5 columns and 4 rows and output an animation of 5x4=20 frames. The frames are placed riw by row in left-to-right order.

It works on any image file in the target folder which respects this regex ^([^\.]+[^\.\d])(\d+)x(\d+)(\.[^\.]+)$.

Raw Packer

The raw packer that accepts a list of file paths and resolves to an object with the atlas json and the image buffer is also exposed:

const { rawPacker } = require("texturepack");

rawPacker(
	[
		"images/img1.png", 
		"images/img2.png", 
		"images/animation2x2.png"
	],
	options
).then(({ image, atlas }) => {
	console.log("packed: ", image, atlas);
});

This accepts the same options, except for folder and outputFolder.

Options

  • folder: [required] folder with images to pack (relative to process.cwd())
  • fileName: specify output file name (without extension, default 'atlas')
  • prettify: whether to prettify the json output file (default false)
  • outFolder: name of the folder where the output files would be written
  • log: whether to log the process (default true in cli usage, false in programmatic usage)
  • packOptions: options for the binpacking of the textures. Details below (defaults to the default values of the pack options).

Pack options:

See also the documentation of maxrect-packer

  • maxWidth: max width of result image (default 1024),
  • maxHeight: max height of result image (default 1024),
  • smart: whether to generate the smallest possible size within limits (default true),
  • pot: whether to generate only power of 2 sized output image (default true),
  • square: whether to force a square output image (default true)
  • padding: padding in pixels around images, useful to avoid artifacts (default 1)