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

View File

@@ -1,6 +1,6 @@
{
"name": "sharp",
"version": "0.4.1",
"version": "0.4.2",
"author": "Lovell Fuller <npm@lovell.info>",
"contributors": [
"Pierre Inglebert <pierre.inglebert@gmail.com>"
@@ -31,7 +31,7 @@
"buffer"
],
"dependencies": {
"nan": "^1.0.0"
"nan": "^1.1.0"
},
"devDependencies": {
"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
double residualx = static_cast<double>(baton->width) / static_cast<double>(shrunk->Xsize);
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);
} else {
residual = std::min(residualx, residualy);
@@ -235,7 +235,7 @@ class ResizeWorker : public NanAsyncWorker {
// Crop/embed
VipsImage *canvased = vips_image_new();
if (affined->Xsize != baton->width || affined->Ysize != baton->height) {
if (baton->crop) {
if (baton->crop || baton->max) {
// Crop/max
int width = std::min(affined->Xsize, baton->width);
int height = std::min(affined->Ysize, baton->height);
@@ -352,14 +352,13 @@ NAN_METHOD(resize) {
baton->width = args[3]->Int32Value();
baton->height = args[4]->Int32Value();
Local<String> canvas = args[5]->ToString();
if (canvas->Equals(NanSymbol("c"))) {
if (canvas->Equals(NanNew<String>("c"))) {
baton->crop = true;
} else if (canvas->Equals(NanSymbol("w"))) {
} else if (canvas->Equals(NanNew<String>("w"))) {
baton->extend = VIPS_EXTEND_WHITE;
} else if (canvas->Equals(NanSymbol("b"))) {
} else if (canvas->Equals(NanNew<String>("b"))) {
baton->extend = VIPS_EXTEND_BLACK;
} else if (canvas->Equals(NanSymbol("m"))) {
baton->crop = true;
} else if (canvas->Equals(NanNew<String>("m"))) {
baton->max = true;
}
baton->sharpen = args[6]->BooleanValue();
@@ -384,9 +383,9 @@ NAN_METHOD(cache) {
// Get cache statistics
Local<Object> cache = NanNew<Object>();
cache->Set(NanSymbol("current"), NanNew<Number>(vips_tracked_get_mem() / 1048576));
cache->Set(NanSymbol("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>("current"), NanNew<Number>(vips_tracked_get_mem() / 1048576));
cache->Set(NanNew<String>("high"), NanNew<Number>(vips_tracked_get_mem_highwater() / 1048576));
cache->Set(NanNew<String>("limit"), NanNew<Number>(vips_cache_get_max_mem() / 1048576));
NanReturnValue(cache);
}

View File

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