Comments (2)
@elmpp did you find a sol to this?
from node-sprite-generator.
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)
- [Error: Could not execute GraphicsMagick/ImageMagick: gm "identify" "-ping" "-format" "%wx%h" "-" this most likely means the gm/convert binaries can't be found] HOT 3
- sprite image is not generating HOT 6
- Could not execute GraphicsMagick/ImageMagick HOT 1
- Getting the following error - Unrecognized option (-Infinity) HOT 3
- Bad compositor / incorrect dependencies even though GraphicsMagick is installed HOT 6
- Support `sharp` as compositor
- gm convert: Unrecognized option (-Infinity) HOT 5
- Pass input source and retrieve output source as buffers HOT 5
- 0.10.2 version is vulnerable, please publish the GitHub changes to npm ? HOT 2
- When can we get next major release? HOT 3
- CLI available? HOT 2
- Update Dependencies HOT 1
- Fails to render custom template... template file name is contents of output stylesheet HOT 4
- grunt command line options are not preserved
- Sprite image and style does not generated HOT 1
- Any way we can use .svg files as well? HOT 1
- JPG support with quality option
- Update canvas dependency version HOT 1
- Error installing node-sprite-generator HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-sprite-generator.