Open elmpp opened 5 years ago
@elmpp did you find a sol to this?
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.
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!');
});
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 %>
}, <% }); %>
]
Hi there,
I'm seeing an error when trying to output javascript styles.
I have tried this with both
gm
andjimp
compositors.error message:
config:
package.json: