Compare commits

..

8 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
Lovell Fuller
6c96bd0d37 Version bumps 2014-05-22 00:18:43 +01:00
Lovell Fuller
6b5f2028b7 Add support for 32 bit Linux #27 2014-05-21 23:46:10 +01:00
5 changed files with 27 additions and 16 deletions

View File

@@ -11,6 +11,7 @@
'/usr/include/glib-2.0', '/usr/include/glib-2.0',
'/usr/lib/glib-2.0/include', '/usr/lib/glib-2.0/include',
'/usr/lib/x86_64-linux-gnu/glib-2.0/include', '/usr/lib/x86_64-linux-gnu/glib-2.0/include',
'/usr/lib/i386-linux-gnu/glib-2.0/include',
'<!(node -e "require(\'nan\')")' '<!(node -e "require(\'nan\')")'
], ],
'cflags': ['-fexceptions', '-pedantic', '-Wall', '-O3'], 'cflags': ['-fexceptions', '-pedantic', '-Wall', '-O3'],

View File

@@ -107,9 +107,13 @@ 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 { } 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; return this;
}; };

View File

@@ -1,6 +1,6 @@
{ {
"name": "sharp", "name": "sharp",
"version": "0.4.0", "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,13 +31,13 @@
"buffer" "buffer"
], ],
"dependencies": { "dependencies": {
"nan": "^1.0.0" "nan": "^1.1.0"
}, },
"devDependencies": { "devDependencies": {
"imagemagick": "^0.1.3", "imagemagick": "^0.1.3",
"imagemagick-native": "git://github.com/mash/node-imagemagick-native.git#master", "imagemagick-native": "^1.0.0",
"gm": "^1.16.0", "gm": "^1.16.0",
"async": "^0.8.0", "async": "^0.9.0",
"benchmark": "^1.0.0" "benchmark": "^1.0.0"
}, },
"license": "Apache 2.0", "license": "Apache 2.0",

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();
});
} }
]); ]);