mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Expose erode and dilate operations #4243
This commit is contained in:
committed by
Lovell Fuller
parent
03e1b19764
commit
031c808aa5
BIN
test/fixtures/dot-and-lines.png
vendored
Normal file
BIN
test/fixtures/dot-and-lines.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 463 B |
BIN
test/fixtures/expected/dilate-1.png
vendored
Normal file
BIN
test/fixtures/expected/dilate-1.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 540 B |
BIN
test/fixtures/expected/erode-1.png
vendored
Normal file
BIN
test/fixtures/expected/erode-1.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 450 B |
2
test/fixtures/index.js
vendored
2
test/fixtures/index.js
vendored
@@ -128,6 +128,8 @@ module.exports = {
|
||||
|
||||
inputJPGBig: getPath('flowers.jpeg'),
|
||||
|
||||
inputPngDotAndLines: getPath('dot-and-lines.png'),
|
||||
|
||||
inputPngStripesV: getPath('stripesV.png'),
|
||||
inputPngStripesH: getPath('stripesH.png'),
|
||||
|
||||
|
||||
@@ -740,3 +740,8 @@ sharp([input, input], {
|
||||
valign: 'bottom'
|
||||
}
|
||||
});
|
||||
|
||||
sharp().erode();
|
||||
sharp().erode(1);
|
||||
sharp().dilate();
|
||||
sharp().dilate(1);
|
||||
|
||||
38
test/unit/dilate.js
Normal file
38
test/unit/dilate.js
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Dilate', function () {
|
||||
it('dilate 1 png', function (done) {
|
||||
sharp(fixtures.inputPngDotAndLines)
|
||||
.dilate(1)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(100, info.width);
|
||||
assert.strictEqual(100, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('dilate-1.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('dilate 1 png - default width', function (done) {
|
||||
sharp(fixtures.inputPngDotAndLines)
|
||||
.dilate()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(100, info.width);
|
||||
assert.strictEqual(100, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('dilate-1.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid dilation width', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).dilate(-1);
|
||||
});
|
||||
});
|
||||
});
|
||||
38
test/unit/erode.js
Normal file
38
test/unit/erode.js
Normal file
@@ -0,0 +1,38 @@
|
||||
'use strict';
|
||||
|
||||
const assert = require('assert');
|
||||
|
||||
const sharp = require('../../');
|
||||
const fixtures = require('../fixtures');
|
||||
|
||||
describe('Erode', function () {
|
||||
it('erode 1 png', function (done) {
|
||||
sharp(fixtures.inputPngDotAndLines)
|
||||
.erode(1)
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(100, info.width);
|
||||
assert.strictEqual(100, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('erode-1.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('erode 1 png - default width', function (done) {
|
||||
sharp(fixtures.inputPngDotAndLines)
|
||||
.erode()
|
||||
.toBuffer(function (err, data, info) {
|
||||
if (err) throw err;
|
||||
assert.strictEqual('png', info.format);
|
||||
assert.strictEqual(100, info.width);
|
||||
assert.strictEqual(100, info.height);
|
||||
fixtures.assertSimilar(fixtures.expected('erode-1.png'), data, done);
|
||||
});
|
||||
});
|
||||
|
||||
it('invalid erosion width', function () {
|
||||
assert.throws(function () {
|
||||
sharp(fixtures.inputJpg).erode(-1);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user