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

@pencil.js/spritesheet

v1.5.1

Published

Pack some images into a spritesheet.

Downloads

131

Readme

Spritesheet Logo

Package size

Pack a set of images into a single spritesheet along its json description file. (CLI version)

Install

npm install @pencil.js/spritesheet

Usage

import spritesheet from "@pencil.js/spritesheet";
import { writeFileSync } from "fs";

// List of files to pack
const files = ["image1.png", "image2.jpg", "image3.gif"];
const options = {
    outputFormat: "png",
};
// Call the async function and extract the json and image values
(async () => {
    const { json, image } = await spritesheet(files, options);
    // Write the files (for example)
    writeFileSync("spritesheet.png", image);
    writeFileSync("spritesheet.json", JSON.stringify(json));
})();

Documentation

spritesheet(files, [options])

The methods accept two arguments.

| Name | Type | Default | Comment | | --- | --- | --- | --- | |files |Array<String> |required |List of paths to the images | |options |Object |(see below) |Some options |

options

You can specify some options on the second argument.

| Name | Type | Default | Comment | | --- | --- | --- | --- | |outputFormat |String |"png" |Format of the output image ("png" or "jpeg") | |outputName |String |"spritesheet.png" |Name of the image file (for reference in the JSON file) | |margin |Number |1 |Added pixels between sprites (can prevent pixels leaking to adjacent sprite) | |crop |Boolean |true |Cut transparent pixels around sprites |

returns

spritesheet returns a Promise for an Object containing a json and image field.

| Name | Type | Comment | | --- | --- | --- | |json |Object |All data related to the spritesheet (example) | |image |Buffer |The result image as a buffer |

JSON

The returned JSON file is composed of two parts:

  • meta - Global data about the generated file
  • frames - Set of all frames/spites with path as key

Each frames gives data about itself:

  • frame - The x, y position on the whole image and w, h for the size
  • rotated - Tell is the sprite have been rotated (not yet supported)
  • trimmed - Tell is the sprite have been cropped
  • spriteSourceSize - The relative x, y position and w, h size
  • sourceSize - The original w, h size

Related

Want to display your generated spritesheet easily on a browser canvas ? Checkout Pencil.js the nice 2D drawing library.

License

MIT