mirror of
https://github.com/lovell/sharp.git
synced 2026-02-04 21:56:18 +01:00
Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bc3311cbad | ||
|
|
7b03eb89d7 | ||
|
|
15a519ebd9 | ||
|
|
3f8e9f6487 | ||
|
|
39688371a8 | ||
|
|
e32faac17a |
8
index.js
8
index.js
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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",
|
||||
|
||||
19
src/sharp.cc
19
src/sharp.cc
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
});
|
||||
}
|
||||
]);
|
||||
|
||||
Reference in New Issue
Block a user