assetgraph-sprite
Advanced tools
Comparing version 0.0.1 to 0.0.2
var _ = require('underscore'), | ||
child_process = require('child_process'), | ||
seq = require('seq'), | ||
@@ -7,2 +8,41 @@ Canvas = require('canvas'), | ||
require('bufferjs'); | ||
function getCanvasImageFromBuffer(buffer, cb) { | ||
var canvasImage = new Canvas.Image(); | ||
canvasImage.onerror = function (err) { | ||
process.nextTick(function () { | ||
cb(err); | ||
}); | ||
}; | ||
canvasImage.onload = function () { | ||
process.nextTick(function () { | ||
cb(null, canvasImage); | ||
}); | ||
}; | ||
canvasImage.src = buffer; | ||
} | ||
function getCanvasImageFromImageAsset(imageAsset, cb) { | ||
imageAsset.getSerializedSrc(passError(cb, function (src) { | ||
if (imageAsset.type === 'Png' || imageAsset.type === 'Jpeg') { | ||
getCanvasImageFromBuffer(src, cb); | ||
} else { | ||
// Use GraphicsMagick while waiting for gif support: https://github.com/LearnBoost/node-canvas/issues/78 | ||
var buffers = [], | ||
convertProcess = child_process.spawn('gm', ['convert', imageAsset.type.toLowerCase() + ':-', 'png:-']); | ||
convertProcess.stdout.on('data', function (buffer) { | ||
buffers.push(buffer); | ||
}); | ||
convertProcess.on('exit', function () { | ||
getCanvasImageFromBuffer(Buffer.concat(buffers), cb); | ||
}).on('error', cb); | ||
convertProcess.stdin.write(src); | ||
convertProcess.stdin.end(); | ||
} | ||
})); | ||
} | ||
function calculateSpritePadding(paddingStr) { | ||
@@ -36,3 +76,3 @@ if (paddingStr) { | ||
if (cairoVersion[0] < 1 || cairoVersion[1] < 10) { | ||
console.warn("transforms.spriteBackgroundImages: Cannot create sprites due to missing canvas.getContext('2d').drawImage() support. Please compile node-canvas with Cairo version 1.10.0 or above."); | ||
console.warn("assetgraph-sprite: Cannot create sprites due to missing canvas.getContext('2d').drawImage() support. Please compile node-canvas with Cairo version 1.10.0 or above."); | ||
return cb(); | ||
@@ -82,3 +122,3 @@ } | ||
if (spriteGroups[spriteGroupName].placeHolder) { | ||
console.warn("spriteBackgroundImages: Multiple definitions of " + spriteGroupName + " sprite"); | ||
console.warn("assetgraph-sprite: Multiple definitions of " + spriteGroupName + " sprite"); | ||
} | ||
@@ -85,0 +125,0 @@ spriteGroups[spriteGroupName].placeHolder = _.extend(spriteInfo, { |
@@ -5,3 +5,3 @@ { | ||
"repository": "git://github.com/One-com/assetgraph-sprite.git", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"maintainers": [ | ||
@@ -15,2 +15,3 @@ { | ||
"underscore": ">=1.1.3", | ||
"bufferjs": "=1.0.1", | ||
"canvas": "=0.6.0", | ||
@@ -17,0 +18,0 @@ "seq": ">=0.3.0 <0.4" |
@@ -28,3 +28,3 @@ var vows = require('vows'), | ||
topic: function (assetGraph) { | ||
assetGraph.queue(transforms.spriteBackgroundImages()).run(this.callback); | ||
assetGraph.queue(require('../lib')()).run(this.callback); | ||
}, | ||
@@ -31,0 +31,0 @@ 'the number of Png assets should be down to one': function (assetGraph) { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Shell access
Supply chain riskThis module accesses the system shell. Accessing the system shell increases the risk of executing arbitrary code.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23938
448
4
1
+ Addedbufferjs@=1.0.1