Skip to content

Commit b807099

Browse files
Fix incorrect implementation for replaceColor with rgb colors (#305)
1 parent 3e9ecbb commit b807099

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

__TESTS__/unit/actions/Adjust.test.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,17 @@ describe('Tests for Transformation Action -- Adjust', () => {
122122
expect(url).toContain('e_replace_color:red:30:blue');
123123
});
124124

125+
it('tests replaceColor with RGB colors', () => {
126+
const url = createNewImage('sample')
127+
.adjust(Adjust
128+
.replaceColor('#fff')
129+
.tolerance(30)
130+
.fromColor('#aaa'))
131+
.toURL();
132+
133+
expect(url).toContain('e_replace_color:fff:30:aaa');
134+
});
135+
125136
it('tests replaceColor - without fromColor', () => {
126137
const url = createNewImage('sample')
127138
.adjust(Adjust.replaceColor('red'))

src/actions/adjust/ReplaceColorAction.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,12 @@ class ReplaceColorAction extends Action {
4949
}
5050

5151
protected prepareQualifiers(): this {
52-
// e_replace_color:red:30:blue
53-
const qualifierValue = new QualifierValue(['replace_color', this.targetColor, this.toleranceLevel, prepareColor(this.baseColor)]);
52+
// Target color and base color might not exist at this point (optional qualifiers)
53+
// If they exist, ensure that any # for RGB are removed from the resulting string
54+
const targetColor = this.targetColor && this.targetColor.toString().replace('#', '');
55+
const baseColor = this.baseColor && this.baseColor.toString().replace('#', '');
56+
57+
const qualifierValue = new QualifierValue(['replace_color', targetColor, this.toleranceLevel, baseColor]);
5458
this.addQualifier(new Qualifier('e', qualifierValue));
5559
return this;
5660
}

0 commit comments

Comments
 (0)