diff --git a/docs/changelog.md b/docs/changelog.md index cbf21df3..ca7be0b0 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -29,6 +29,10 @@ [#347](https://github.com/lovell/sharp/issues/347) [@oaleynik](https://github.com/oaleynik) +* Ensure default crop gravity is center/centre. + [#351](https://github.com/lovell/sharp/pull/351) + [@joelmukuthu](https://github.com/joelmukuthu) + * Small optimisation when reducing by an integral factor to favour shrink over affine. * Add support for gamma correction of images with an alpha channel. diff --git a/src/pipeline.cc b/src/pipeline.cc index 8efd1154..b92ccd8c 100644 --- a/src/pipeline.cc +++ b/src/pipeline.cc @@ -39,6 +39,7 @@ using Nan::Equals; using vips::VImage; using vips::VInterpolate; +using vips::VOption; using vips::VError; using sharp::Composite; @@ -222,11 +223,11 @@ class PipelineWorker : public AsyncWorker { inputImageType = DetermineImageType(baton->bufferIn, baton->bufferInLength); if (inputImageType != ImageType::UNKNOWN) { try { - image = VImage::new_from_buffer( - baton->bufferIn, baton->bufferInLength, nullptr, VImage::option() - ->set("access", baton->accessMethod) - ->set("density", baton->density.data()) - ); + VOption *option = VImage::option()->set("access", baton->accessMethod); + if (inputImageType == ImageType::MAGICK) { + option->set("density", baton->density.data()); + } + image = VImage::new_from_buffer(baton->bufferIn, baton->bufferInLength, nullptr, option); } catch (...) { (baton->err).append("Input buffer has corrupt header"); inputImageType = ImageType::UNKNOWN; @@ -240,11 +241,11 @@ class PipelineWorker : public AsyncWorker { inputImageType = DetermineImageType(baton->fileIn.data()); if (inputImageType != ImageType::UNKNOWN) { try { - image = VImage::new_from_file( - baton->fileIn.data(), VImage::option() - ->set("access", baton->accessMethod) - ->set("density", baton->density.data()) - ); + VOption *option = VImage::option()->set("access", baton->accessMethod); + if (inputImageType == ImageType::MAGICK) { + option->set("density", baton->density.data()); + } + image = VImage::new_from_file(baton->fileIn.data(), option); } catch (...) { (baton->err).append("Input file has corrupt header"); inputImageType = ImageType::UNKNOWN; diff --git a/test/bench/package.json b/test/bench/package.json index 00562e1d..b4c08fbd 100644 --- a/test/bench/package.json +++ b/test/bench/package.json @@ -5,7 +5,7 @@ "author": "Lovell Fuller ", "description": "Benchmark and performance tests for sharp", "scripts": { - "test": "node perf && node random && node parallel" + "test": "VIPS_WARNING=0 node perf && node random && node parallel" }, "devDependencies": { "async": "^1.5.2",