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