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

openmoji-spritemap-generator

v2.1.4

Published

Generate sprite sheets from OpenMoji emojis

Downloads

77

Readme

openmoji-spritemap-generator

This lib generates merged sprite sheets from OpenMoji emojis. A sprite sheet is an image that is composed from smaller images and where every small image has a known position. Emoji sprite sheets allow web developers to build emoji pickers by reducing number of individual images from hundreds to just a few, thus making web sites and apps load quickly.

In addition to sprite sheet images, either PNG or SVG, this lib generates a CSS, HTML, and JSON data files that each contains the emoji positions. The CSS uses the background-position method and the HTML represents the sheet with <map> and <area> tags. The JSON is targeted for custom usage. Pick the one that suits you the best.

For pre-generated sprite sheets, see openmoji-sprites.

Example output

Smileys Emotion   Animals Nature

Sprite sheets, HTML snippets, CSS sprites, and JSON sprite data.

Usage

For instructions how to use the generated sheets, see CSS Sprites article by CSS-Tricks. For instructions how to use the generator, see below.

There is two intended ways to use the generator. The first is by installing it as a Node.js module into your own project and commanding it via API. The second way is more standalone, and allows you to generate sprite sheets without a host project.

Both ways require you to download the OpenMoji emojis and their associated metadata to your project directory. OpenMoji provides multiple alternative sets in different formats, colors and sizes. Therefore it is up to you which emoji set to use. Use the following to download latest 72px wide colored emojis and their metadata.

$ wget https://github.com/hfg-gmuend/openmoji/releases/latest/download/openmoji-72x72-color.zip
$ wget https://github.com/hfg-gmuend/openmoji/raw/master/data/openmoji.json

You need to unzip the emoji zip package and place the directory next to openmoji.json. You will give paths to these two in the next step.

Usage via API

First, install the module into your project via NPM:

$ npm install openmoji-spritemap-generator

Second, include it in your source code with the emoji metadata:

const generate = require('openmoji-spritemap-generator')
const mojis = require('openmoji.json')

Third, provide configuration object. You need to specify the path to the unzipped emoji directory and target directory for the generated files. See the API docs further below for details.

generate({
  name: 'animals-nature',
  emojis: mojis.filter(moji => moji.group === 'animals-nature'),
  emojiDir: 'openmoji-72x72-color',
  targetDir: 'target',
  emojiSize: 72,
  columns: 10,
  backgroundColor: '#FFFFFF00'
}, (err) => {
  if (err) { throw err }
  console.log('Spritemap generated!')
})

Finally, admire the fresh sprite sheets under target/!

Usage as standalone project

First, clone this repository to your machine.

$ git clone <git url to this repo>
$ cd openmoji-spritemap-generator

Second, install dependencies (and the emojis, see above).

$ npm install

Third, modify the default configuration in run.js as you wish. The default behaviour will first group the emojis by their group classes and then call generate for each group separately.

Fourth, check your code for errors.

$ npm test

If code ok then run it. Multiple sprite sheets will be generated under target/.

$ npm start

Finally, see the merged sheets and image map HTML under target/.

API

generate(config, callback)

Generates a sprite sheet image, a CSS sheet, a sprite data JSON, and an image map HTML snippet. Takes in configuration object and a callback function. The callback is invoked after generation has finished and with err if an error occurred.

The configuration object config can take following options.

  • name: A string. A unique name for this emoji set. Affects file prefixes, html classes, and console output.
  • emojis: An array of emoji objects originating from openmoji.json. The order defines the order in the output.
  • mode: Either 'png' or 'svg'. Do we merge PNG or SVG images. Default is 'png'.
  • emojiDir: A directory path to emoji images, either PNG or SVG downloaded from OpenMoji.
  • targetDir: A directory path where to save the generated files.
  • emojiSize: An integer. The pixel width (=height) of emojis in emojiDir. Default is 72.
  • columns: An integer. How many emojis to place on a single sprite sheet row. Default is 10.
  • backgroundColor: A string, parsed by color. Transparent by default.

Additional notes:

  • Resizing emojis is not currently supported. You must resize the emojis beforehand and provide matching emojiSize.

Known problems

Bus error: 10

Happens at least on macOS 10.14 with Node 8.15, Node 10.20, and Node 12.16 when there is more than 200 emojis to be merged. Cause unsure but has something to do with memory management. As a quick workaround, try to merge less emojis.

See also

Licence

The generated sprite sheets are licensed under CC-BY-SA 4.0. The source code is licensed under MIT License.