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

@ksv90/texture-packer

v0.2.8

Published

texture-packer

Downloads

34

Readme

texture-packer

to install the package

npm install @ksv90/texture-packer

to pack textures

npx assets-pack assets-config.json

config

A config is a json file described according to the schemas/config-schema.json scheme.
For autocomplete, the schema can be included in the configuration file: "$schema": "./node_modules/@ksv90/texture-packer/schemas/config-schema.json"

examples

In the examples directory on github you can see a simple working example of a configuration file and texture packaging. Locally, you can run packaging using the assets-pack script from the package.json file.

{
  "$schema": "./node_modules/@ksv90/texture-packer/schemas/config-schema.json",
  "settings": [
    {
      "sourceDir": "examples",
      "targetDir": "examples/public",
      "sourceList": ["textures"],
      "details": {
        "textures": {
          "t3.png": { "scale": 0.5 },
          "t1.png": { "scale": 0.25 }
        }
      },
      "addTextures": {
        "textures": ["add/t5.png"]
      },
      "output": [
        { "format": "png", "width": 4096, "height": 4096, "suffix": "@1.0" },
        { "format": "webp", "width": 2048, "height": 2048, "subDir": "webp" }
      ]
    }
  ]
}

settings

The configuration file accepts an array of settings. The settings are needed for the packager so that he understands what needs to be done.
The configuration below shows how parameters can be passed for multiple input points.

{
  "settings": [
    {
      "sourceDir": "assets",
      "targetDir": "public",
      "sourceList": ["directory-one", "directory-two"],
      "subDir": "desktop",
      "output": [{ "format": "webp", "subDir": "desktop", "width": 1024, "height": 1024 }]
    },
    {
      "sourceDir": "assets",
      "targetDir": "public",
      "sourceList": ["directory-one", "directory-two"],
      "subDir": "mobile",
      "output": [{ "format": "webp", "subDir": "mobile", "width": 1024, "height": 1024 }]
    }
  ]
}

The optional subDir parameters for settings and output are specified here. This settings will read files in directories and write the result to disk like this:
assets/directory-one/desktop/** -> public/directory-one/desktop/**
assets/directory-two/desktop/** -> public/directory-two/desktop/**
assets/directory-one/mobile/** -> public/directory-one/mobile/**
assets/directory-two/mobile/** -> public/directory-two/mobile/**

output

In turn, the read stream can be converted into several output streams.
Below is the export in WebP and PNG formats:

{
  "settings": [
    {
      "sourceDir": "assets",
      "targetDir": "public",
      "sourceList": ["directory-one", "directory-two"],
      "output": [
        { "format": "webp", "subDir": "webp", "width": 1024, "height": 1024 },
        { "format": "png", "subDir": "png", "width": 1024, "height": 1024 }
      ]
    }
  ]
}

output params

You can set various parameters for the output stream:

  • width - maximum output sprite width
  • height - maximum output sprite height
  • scale - scale - to resize the texture before adding it to the output sprite
  • name - the name of the output sprite and configuration file (default - sprite)
  • suffix - postscript after the output file name ("suffix": "@1.0" -> [email protected])
  • background — background color of the output file (relevant for jpg format)
  • metaScale - prints information to the sprite configuration file that the texture scale has been changed (for example, if you specify a value of 2, pixi.js will automatically reduce the size by 2 times)

details

If you need detailed settings for each texture, you can specify parameters in the details field:

{
  "settings": [
    {
      "sourceDir": "assets",
      "targetDir": "public",
      "sourceList": ["directory-one", "directory-two"],
      "details": {
        "directory-one": {
          "texture-1": {
            "scale": 0.5
          }
        }
      },
      "output": [{ "format": "webp", "width": 1024, "height": 1024, "scale": 0.5 }]
    }
  ]
}

Here, for all textures in the directories directory-one and directory-two a scale of 0.5 will be applied. And for the texture called texture-1.png in the directory-one directory, a scale of 0.25 will be applied (multiplying the values 0.5 * 0.5)

add-textures

Sometimes it can be useful to add a texture from a different directory to the sprite. This can be done using addTextures:

{
  "settings": [
    {
      "sourceDir": "assets",
      "targetDir": "public",
      "sourceList": ["directory-one", "directory-two"],
      "addTextures": {
        "directory-one": ["other-directory/special-texture.png"]
      },
      "output": [{ "format": "webp", "width": 1024, "height": 1024 }]
    }
  ]
}

Here, the output sprite directory-one will contain textures from the assets/directory-one directory, as well as the assets/other-directory/special-texture.png texture. The output sprite directory-two will only contain textures from assets/directory-two.

allow-rotation

By default, the packer flips textures if it helps reduce the size of the output sprite. With the allowRotation setting you can disable this behavior:

{
  "allowRotation": false,
  "settings": [
    {
      "targetDir": "assets",
      "sourceList": ["textures"],
      "output": [{ "format": "webp", "width": 1024, "height": 1024 }]
    }
  ]
}

cache

By default, after packaging, a simple cache will be created to optimize the repackaging process.
If this is not what you need, you can disable it by setting "cache": false. You can also specify the name and location of the cache information file using the cacheName parameter:

{
  "cache": true,
  "cacheName": "public/.assets-cache",
  "settings": [
    {
      "targetDir": "public",
      "sourceList": ["textures"],
      "output": [{ "format": "webp", "width": 1024, "height": 1024 }]
    }
  ]
}