Skip to content

Commit 63ae5e2

Browse files
feat: add the normalize directive
1 parent 0d703c1 commit 63ae5e2

File tree

3 files changed

+32
-1
lines changed

3 files changed

+32
-1
lines changed

docs/directives.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,3 +205,17 @@ Produces a 'negative' of the image.
205205
import Image from 'example.jpg?invert'
206206
import Image from 'exmaple.jpg?invert=true'
207207
```
208+
___
209+
210+
### Invert
211+
**Keyword**: `invert`
212+
**Type**: _boolean_
213+
214+
'Normalizes' the image by stretching its luminance to cover the full dynamic range.
215+
This Eenhances the output image contrast.
216+
217+
**Example**:
218+
```js
219+
import Image from 'example.jpg?invert'
220+
import Image from 'exmaple.jpg?invert=true'
221+
```

src/directives/index.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,5 @@ export * from './rotate'
44
export * from './flip'
55
export * from './flop'
66
export * from './blur'
7-
export * from './invert'
7+
export * from './invert'
8+
export * from './normalize'

src/directives/normalize.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import { Directive, DirectiveContext, DirectiveOptions } from "../types";
2+
3+
interface FlipOptions {
4+
normalize: string
5+
}
6+
7+
export const normalize:Directive<FlipOptions> = ({ normalize }: DirectiveOptions, ctx: DirectiveContext) => {
8+
if (normalize !== '' && normalize !== 'true') return null
9+
10+
ctx.useParam('normalize')
11+
ctx.setMetadata('normalize', true)
12+
13+
return function normalizeTransform(image) {
14+
return image.normalize()
15+
}
16+
}

0 commit comments

Comments
 (0)