mirror of
https://github.com/lovell/sharp.git
synced 2026-02-04 05:36:18 +01:00
Add margin option to trim operation #4480
This commit is contained in:
committed by
Lovell Fuller
parent
d161e45e06
commit
a5e726002c
@@ -326,3 +326,6 @@ GitHub: https://github.com/tpatel
|
||||
|
||||
Name: Maël Nison
|
||||
GitHub: https://github.com/arcanis
|
||||
|
||||
Name: Dmytro Tiapukhin
|
||||
GitHub: https://github.com/eddienubes
|
||||
|
||||
@@ -284,6 +284,7 @@ The `info` response Object will contain `trimOffsetLeft` and `trimOffsetTop` pro
|
||||
| [options.background] | <code>string</code> \| <code>Object</code> | <code>"'top-left pixel'"</code> | Background colour, parsed by the [color](https://www.npmjs.org/package/color) module, defaults to that of the top-left pixel. |
|
||||
| [options.threshold] | <code>number</code> | <code>10</code> | Allowed difference from the above colour, a positive number. |
|
||||
| [options.lineArt] | <code>boolean</code> | <code>false</code> | Does the input more closely resemble line art (e.g. vector) rather than being photographic? |
|
||||
| [options.margin] | <code>number</code> | <code>0</code> | Leave a margin around trimmed content, value is in pixels. |
|
||||
|
||||
**Example**
|
||||
```js
|
||||
@@ -320,4 +321,13 @@ const output = await sharp(input)
|
||||
threshold: 42,
|
||||
})
|
||||
.toBuffer();
|
||||
```
|
||||
**Example**
|
||||
```js
|
||||
// Trim image leaving (up to) a 10 pixel margin around the trimmed content.
|
||||
const output = await sharp(input)
|
||||
.trim({
|
||||
margin: 10
|
||||
})
|
||||
.toBuffer();
|
||||
```
|
||||
@@ -34,4 +34,8 @@ slug: changelog/v0.35.0
|
||||
* TypeScript: Ensure `FormatEnum` keys match reality.
|
||||
[#4475](https://github.com/lovell/sharp/issues/4475)
|
||||
|
||||
* Add `margin` option to `trim` operation.
|
||||
[#4480](https://github.com/lovell/sharp/issues/4480)
|
||||
[@eddienubes](https://github.com/eddienubes)
|
||||
|
||||
* Add WebP `exact` option for control over transparent pixel colour values.
|
||||
|
||||
Reference in New Issue
Block a user