GithubHelp home page GithubHelp logo

Comments (2)

navjeetfgmnt avatar navjeetfgmnt commented on September 4, 2024

@elmpp did you find a sol to this?

from node-sprite-generator.

timohausmann avatar timohausmann commented on September 4, 2024

Same, there is no "javascript" template in this repository.
I found two workarounds, these examples will create a json format, adjust the output to your likings.

Workaround 1: write custom output function

I think the easiest way is to set options.stylesheet to a custom function:

var nsg = require('node-sprite-generator');
var fs = require('fs');

nsg({
    src: [
        'faces-128/*.jpg'
    ],
    spritePath: 'faces-128/all.png',
    stylesheetPath: 'faces-128/all.json',
    stylesheet: function(layout, stylesheetPath, spritePath, options, callback) {
      const data = layout.images.map((img) => {
        const {x, y, width, height, path} = img;
        return { x, y, width, height, path }
      })

      fs.writeFileSync(stylesheetPath, JSON.stringify(data, null, 2))
    },
    compositor: 'jimp'
}, function (err) {
    console.log('Sprite generated!');
});

Workaround 2: add missing templates

You can also create the missing templates.

create new file node-sprite-generator/lib/stylesheet/javascript.js:

'use strict';

var getTemplatedStylesheet = require('./templatedStylesheet'),
    path = require('path');

module.exports = getTemplatedStylesheet(path.join(__dirname, '/templates/javascript.tpl'));

create new file node-sprite-generator/lib/stylesheet/templates/javascript.tpl:

[<% layout.images.forEach(function (image) { %>
  {
    "path": "<%= image.path %>",
    "x": <%= image.x %>,
    "y": <%= image.y %>,
    "width": <%= image.width %>,
    "height": <%= image.height %>
  }, <% }); %>
]

from node-sprite-generator.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.