limby-resize
Advanced tools
Comparing version 0.0.3 to 0.0.5
@@ -0,1 +1,2 @@ | ||
var when = require('when'); | ||
/* | ||
@@ -5,3 +6,3 @@ * MIT License | ||
* https://github.com/danschumann/limby-resize | ||
* 0.0.1 | ||
* 0.0.4 | ||
*/ | ||
@@ -46,3 +47,3 @@ var canvasResize = function(original, canvas) { | ||
// For every pixel in the original, we tally it up in the new one | ||
for (var y1 = 0; y1 < h1; y1++){ | ||
var nextY = function(y1){ | ||
for (var x1 = 0; x1 < w1; x1++) { | ||
@@ -147,21 +148,37 @@ | ||
}; | ||
if (y1++ < h1) | ||
setTimeout(nextY.bind(this, y1), 0); // this allows other processes to tick | ||
else | ||
done(); | ||
}; | ||
// fully distribute the color of pixels that are partially full because their neighbor is transparent | ||
for (var i = 0; i < (_data2.length >> 2); i++){ | ||
if (alphas[i] && alphas[i] < 1) { | ||
data2[(i<<2)] /= alphas[i]; // r | ||
data2[(i<<2) + 1] /= alphas[i]; // g | ||
data2[(i<<2) + 2] /= alphas[i]; // b | ||
nextY(0); | ||
var done = function(){ | ||
// fully distribute the color of pixels that are partially full because their neighbor is transparent | ||
for (var i = 0; i < (_data2.length >> 2); i++){ | ||
if (alphas[i] && alphas[i] < 1) { | ||
data2[(i<<2)] /= alphas[i]; // r | ||
data2[(i<<2) + 1] /= alphas[i]; // g | ||
data2[(i<<2) + 2] /= alphas[i]; // b | ||
} | ||
} | ||
} | ||
// re populate the actual imgData | ||
for (var i = 0; i < data2.length; i++){ | ||
_data2[i] = Math.round(data2[i]); | ||
} | ||
// re populate the actual imgData | ||
for (var i = 0; i < data2.length; i++){ | ||
_data2[i] = Math.round(data2[i]); | ||
} | ||
var context = canvas.getContext("2d") | ||
context.putImageData(img2, 0, 0); | ||
var context = canvas.getContext("2d") | ||
context.putImageData(img2, 0, 0); | ||
deferred.resolve(); | ||
}; | ||
var deferred = when.defer(); | ||
return deferred.promise | ||
}; | ||
@@ -168,0 +185,0 @@ |
@@ -46,13 +46,15 @@ /* | ||
resizedCanvas = new Canvas(width, height); | ||
canvasResize(canvas, resizedCanvas); | ||
} | ||
}; | ||
var deferred = when.defer(); | ||
(resizedCanvas || canvas).toBuffer(function(err, buf){ | ||
return fs.writeFile(options.destination, buf) | ||
.then(deferred.resolve).otherwise(deferred.reject); | ||
}); | ||
return when(canvasResize(canvas, resizedCanvas)) | ||
.then(function(){ | ||
var deferred = when.defer(); | ||
(resizedCanvas || canvas).toBuffer(function(err, buf){ | ||
return fs.writeFile(options.destination, buf) | ||
.then(deferred.resolve).otherwise(deferred.reject); | ||
}); | ||
return deferred.promise; | ||
return deferred.promise; | ||
}); | ||
}; | ||
@@ -59,0 +61,0 @@ }) |
{ | ||
"name": "limby-resize", | ||
"version": "0.0.3", | ||
"version": "0.0.5", | ||
"description": "Wrapper for resizing using ImageMagick OR Canvas.", | ||
@@ -5,0 +5,0 @@ "main": "./limby-resize.js", |
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
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
15168
253