Skip to content

Commit 505cdf8

Browse files
author
Jack Rimell
committed
adding background color option
1 parent 6362b4e commit 505cdf8

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

Docs/Api.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,20 @@ rotate the image
226226

227227
> Optionally, a resize mode can be passed. If `false` is passed as the second parameter, the image width and height will not be resized.
228228
229+
### background
230+
231+
sets the color of any new pixels generated by the image. Will be visible when applying other values such as rotate.
232+
233+
**Type** - `Hexidecimal rgba`,
234+
235+
**Default** - `AUTO`
236+
237+
**Example** -
238+
239+
```jsx
240+
<ProcessImage image={image} background={0x00ff001c} />
241+
```
242+
229243
### brightness
230244

231245
change the brightness level of an image. It takes value from `-1` to `1`.

src/utils/options.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ function processImage(image, props, ROOT) {
2222
opacity,
2323
blur,
2424
posterize,
25-
crop
25+
crop,
26+
background
2627
} = props;
2728

2829
function MODE(algorithm) {
@@ -170,6 +171,12 @@ function processImage(image, props, ROOT) {
170171
: image.pass(image);
171172
};
172173

174+
image.__proto__.applyBackground = function(image, background) {
175+
return background !== undefined
176+
? image.background(background)
177+
: image.pass(image);
178+
};
179+
173180
image.__proto__.changeBrightness = function(image, brightness) {
174181
return changeImageAppearence(brightness, image, 'brightness');
175182
};
@@ -204,6 +211,7 @@ function processImage(image, props, ROOT) {
204211

205212
return image
206213
.clone()
214+
.applyBackground(image, background)
207215
.resizeAnImage(image, resize)
208216
.changeImageQuality(image, quality)
209217
.applyGreyscale(image, greyscale)

src/utils/propsFactory.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ const filterPropsToListen = props => {
2121
opacity,
2222
blur,
2323
posterize,
24-
colors
24+
colors,
25+
background
2526
} = props;
2627

2728
return {
@@ -46,7 +47,8 @@ const filterPropsToListen = props => {
4647
opacity,
4748
blur,
4849
posterize,
49-
colors
50+
colors,
51+
background
5052
};
5153
};
5254

@@ -82,6 +84,7 @@ const getImageProps = props => {
8284
disableRerender,
8385
customCdn,
8486
onProcessFinish,
87+
background,
8588
...rest
8689
} = props;
8790

0 commit comments

Comments
 (0)