mirror of
https://github.com/lovell/sharp.git
synced 2025-12-19 07:15:08 +01:00
Add ability to extend (pad) the edges of an image
This commit is contained in:
21
docs/api.md
21
docs/api.md
@@ -280,7 +280,7 @@ sharp(input)
|
||||
|
||||
#### background(rgba)
|
||||
|
||||
Set the background for the `embed` and `flatten` operations.
|
||||
Set the background for the `embed`, `flatten` and `extend` operations.
|
||||
|
||||
`rgba` is parsed by the [color](https://www.npmjs.org/package/color) module to extract values for red, green, blue and alpha.
|
||||
|
||||
@@ -292,6 +292,25 @@ The default background is `{r: 0, g: 0, b: 0, a: 1}`, black without transparency
|
||||
|
||||
Merge alpha transparency channel, if any, with `background`.
|
||||
|
||||
#### extend(extension)
|
||||
|
||||
Extends/pads the edges of the image with `background`, where `extension` is one of:
|
||||
|
||||
* a Number representing the pixel count to add to each edge, or
|
||||
* an Object containing `top`, `left`, `bottom` and `right` attributes, each a Number of pixels to add to that edge.
|
||||
|
||||
This operation will always occur after resizing and extraction, if any.
|
||||
|
||||
```javascript
|
||||
// Resize to 140 pixels wide, then add 10 transparent pixels
|
||||
// to the top, left and right edges and 20 to the bottom edge
|
||||
sharp(input)
|
||||
.resize(140)
|
||||
.background({r: 0, g: 0, b: 0, a: 0})
|
||||
.extend({top: 10, bottom: 20, left: 10, right: 10})
|
||||
...
|
||||
```
|
||||
|
||||
#### negate()
|
||||
|
||||
Produces the "negative" of the image. White => Black, Black => White, Blue => Yellow, etc.
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
### v0.14 - "*needle*"
|
||||
|
||||
* Add ability to extend (pad) the edges of an image.
|
||||
[#128](https://github.com/lovell/sharp/issues/128)
|
||||
[@blowsie](https://github.com/blowsie)
|
||||
|
||||
* Improvements to overlayWith: differing sizes/formats, gravity, buffer input.
|
||||
[#239](https://github.com/lovell/sharp/issues/239)
|
||||
[@chrisriley](https://github.com/chrisriley)
|
||||
|
||||
Reference in New Issue
Block a user