Compare commits

..

6 Commits

Author SHA1 Message Date
Lovell Fuller
bc3311cbad Version bump 2014-05-26 09:23:41 +01:00
Lovell Fuller
7b03eb89d7 Merge pull request #39 from pierreinglebert/update-nan
update to nan 1.1.0
2014-05-26 09:15:35 +01:00
Pierre Inglebert
15a519ebd9 update to nan 1.1.0 2014-05-26 09:51:53 +02:00
Lovell Fuller
3f8e9f6487 Merge pull request #38 from pierreinglebert/fix-max-cropping-29
fix max factor #29
2014-05-24 11:54:59 +01:00
Pierre Inglebert
39688371a8 fix max factor #29 2014-05-24 10:29:33 +02:00
Lovell Fuller
e32faac17a Prevent writing output file over input file - closes #28 2014-05-22 22:27:02 +01:00
4 changed files with 24 additions and 14 deletions

View File

@@ -107,10 +107,14 @@ Sharp.prototype.resize = function(width, height) {
Sharp.prototype.write = function(output, callback) { Sharp.prototype.write = function(output, callback) {
if (!output || output.length === 0) { if (!output || output.length === 0) {
throw 'Invalid output'; callback('Invalid output');
} else {
if (this.options.inFile === output) {
callback('Cannot use same file for input and output');
} else { } else {
this._sharp(output, callback); this._sharp(output, callback);
} }
}
return this; return this;
}; };

View File

@@ -1,6 +1,6 @@
{ {
"name": "sharp", "name": "sharp",
"version": "0.4.1", "version": "0.4.2",
"author": "Lovell Fuller <npm@lovell.info>", "author": "Lovell Fuller <npm@lovell.info>",
"contributors": [ "contributors": [
"Pierre Inglebert <pierre.inglebert@gmail.com>" "Pierre Inglebert <pierre.inglebert@gmail.com>"
@@ -31,7 +31,7 @@
"buffer" "buffer"
], ],
"dependencies": { "dependencies": {
"nan": "^1.0.0" "nan": "^1.1.0"
}, },
"devDependencies": { "devDependencies": {
"imagemagick": "^0.1.3", "imagemagick": "^0.1.3",

View File

@@ -211,7 +211,7 @@ class ResizeWorker : public NanAsyncWorker {
// Recalculate residual float based on dimensions of required vs shrunk images // Recalculate residual float based on dimensions of required vs shrunk images
double residualx = static_cast<double>(baton->width) / static_cast<double>(shrunk->Xsize); double residualx = static_cast<double>(baton->width) / static_cast<double>(shrunk->Xsize);
double residualy = static_cast<double>(baton->height) / static_cast<double>(shrunk->Ysize); double residualy = static_cast<double>(baton->height) / static_cast<double>(shrunk->Ysize);
if (baton->crop) { if (baton->crop || baton->max) {
residual = std::max(residualx, residualy); residual = std::max(residualx, residualy);
} else { } else {
residual = std::min(residualx, residualy); residual = std::min(residualx, residualy);
@@ -235,7 +235,7 @@ class ResizeWorker : public NanAsyncWorker {
// Crop/embed // Crop/embed
VipsImage *canvased = vips_image_new(); VipsImage *canvased = vips_image_new();
if (affined->Xsize != baton->width || affined->Ysize != baton->height) { if (affined->Xsize != baton->width || affined->Ysize != baton->height) {
if (baton->crop) { if (baton->crop || baton->max) {
// Crop/max // Crop/max
int width = std::min(affined->Xsize, baton->width); int width = std::min(affined->Xsize, baton->width);
int height = std::min(affined->Ysize, baton->height); int height = std::min(affined->Ysize, baton->height);
@@ -352,14 +352,13 @@ NAN_METHOD(resize) {
baton->width = args[3]->Int32Value(); baton->width = args[3]->Int32Value();
baton->height = args[4]->Int32Value(); baton->height = args[4]->Int32Value();
Local<String> canvas = args[5]->ToString(); Local<String> canvas = args[5]->ToString();
if (canvas->Equals(NanSymbol("c"))) { if (canvas->Equals(NanNew<String>("c"))) {
baton->crop = true; baton->crop = true;
} else if (canvas->Equals(NanSymbol("w"))) { } else if (canvas->Equals(NanNew<String>("w"))) {
baton->extend = VIPS_EXTEND_WHITE; baton->extend = VIPS_EXTEND_WHITE;
} else if (canvas->Equals(NanSymbol("b"))) { } else if (canvas->Equals(NanNew<String>("b"))) {
baton->extend = VIPS_EXTEND_BLACK; baton->extend = VIPS_EXTEND_BLACK;
} else if (canvas->Equals(NanSymbol("m"))) { } else if (canvas->Equals(NanNew<String>("m"))) {
baton->crop = true;
baton->max = true; baton->max = true;
} }
baton->sharpen = args[6]->BooleanValue(); baton->sharpen = args[6]->BooleanValue();
@@ -384,9 +383,9 @@ NAN_METHOD(cache) {
// Get cache statistics // Get cache statistics
Local<Object> cache = NanNew<Object>(); Local<Object> cache = NanNew<Object>();
cache->Set(NanSymbol("current"), NanNew<Number>(vips_tracked_get_mem() / 1048576)); cache->Set(NanNew<String>("current"), NanNew<Number>(vips_tracked_get_mem() / 1048576));
cache->Set(NanSymbol("high"), NanNew<Number>(vips_tracked_get_mem_highwater() / 1048576)); cache->Set(NanNew<String>("high"), NanNew<Number>(vips_tracked_get_mem_highwater() / 1048576));
cache->Set(NanSymbol("limit"), NanNew<Number>(vips_cache_get_max_mem() / 1048576)); cache->Set(NanNew<String>("limit"), NanNew<Number>(vips_cache_get_max_mem() / 1048576));
NanReturnValue(cache); NanReturnValue(cache);
} }

View File

@@ -145,5 +145,12 @@ async.series([
done(); done();
}); });
}); });
},
// Attempt to output to input, should fail
function(done) {
sharp(inputJpg).write(inputJpg, function(err) {
assert(!!err);
done();
});
} }
]); ]);