@@ -609,6 +609,16 @@ class PipelineWorker : public Napi::AsyncWorker {
609609 image = sharp::Threshold (image, baton->threshold , baton->thresholdGrayscale );
610610 }
611611
612+ // Dilate - must happen before blurring, due to the utility of dilating after thresholding
613+ if (baton->dilateWidth != 0 ) {
614+ image = sharp::Dilate (image, baton->dilateWidth );
615+ }
616+
617+ // Erode - must happen before blurring, due to the utility of eroding after thresholding
618+ if (baton->erodeWidth != 0 ) {
619+ image = sharp::Erode (image, baton->erodeWidth );
620+ }
621+
612622 // Blur
613623 if (shouldBlur) {
614624 image = sharp::Blur (image, baton->blurSigma , baton->precision , baton->minAmpl );
@@ -1621,6 +1631,8 @@ Napi::Value pipeline(const Napi::CallbackInfo& info) {
16211631 baton->gammaOut = sharp::AttrAsDouble (options, " gammaOut" );
16221632 baton->linearA = sharp::AttrAsVectorOfDouble (options, " linearA" );
16231633 baton->linearB = sharp::AttrAsVectorOfDouble (options, " linearB" );
1634+ baton->dilateWidth = sharp::AttrAsUint32 (options, " dilateWidth" );
1635+ baton->erodeWidth = sharp::AttrAsUint32 (options, " erodeWidth" );
16241636 baton->greyscale = sharp::AttrAsBool (options, " greyscale" );
16251637 baton->normalise = sharp::AttrAsBool (options, " normalise" );
16261638 baton->normaliseLower = sharp::AttrAsUint32 (options, " normaliseLower" );
0 commit comments