Skip to content

Commit

Permalink
add jxl, nix hiec
Browse files Browse the repository at this point in the history
  • Loading branch information
moorejs committed Nov 1, 2023
1 parent befee19 commit 5dce66b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
9 changes: 5 additions & 4 deletions docs/directives.md
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ The effect of effort varies per format, but a lower value leads to faster encodi
The supported ranges by format:
- `png`: 1 to 10 (default 7)
- `webp`: 0 to 6 (default 4)
- `avif`/`heif`/`heic`: 0 to 9 (default 4)
- `avif`/`heif`: 0 to 9 (default 4)
- `jxl`: 3 to 9 (default 7)
- `gif`: 1 to 10 (default 7)

The keywords `"min"` and `"max"` apply the highest effort value for the given image format.
Expand Down Expand Up @@ -168,7 +169,7 @@ import Image from 'exmaple.jpg?flop=true'

### Format

**Keyword**: `format`<br> • **Type**: _heic_\| _heif_ \| _avif_ \| _jpeg_ \| _jpg_ \| _png_ \| _tiff_ \| _webp_ \|
**Keyword**: `format`<br> • **Type**: _jxl_\| _heif_ \| _avif_ \| _jpeg_ \| _jpg_ \| _png_ \| _tiff_ \| _webp_ \|
_gif_<br>

Convert the image into the given format.
Expand All @@ -180,7 +181,7 @@ Convert the image into the given format.

```js
import Image from 'example.jpg?format=webp'
import Images from 'example.jpg?format=webp;avif;heic'
import Images from 'example.jpg?format=webp;avif;jxl'
```

---
Expand Down Expand Up @@ -259,7 +260,7 @@ Use this directive to set a different interpolation kernel when resizing the ima
Use lossless compression mode.

Formats that support this directive are:
`avif`, `heif`, `heic`, and `webp`
`avif`, `heif`, `jxl`, and `webp`

**Example**:

Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/transforms/__tests__/effort.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('effort', () => {
})

it('ignores effort when not applicable', async () => {
img[METADATA] = { format: 'jpeg' }
img[METADATA] = { format: 'tiff' }
const res = getEffort({ effort: 'max' }, img)

expect(res).toBeUndefined()
Expand Down
11 changes: 6 additions & 5 deletions packages/core/src/transforms/effort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,13 @@ export interface EffortOptions {
}

const FORMAT_TO_EFFORT_RANGE: Record<string, [number, number]> = {
png: [1, 10],
webp: [0, 6],
avif: [0, 9],
heif: [0, 9],
heic: [0, 9],
gif: [1, 10]
gif: [1, 10],
jpeg: [0, 9],
jpg: [0, 9],
jxl: [3, 9],
png: [1, 10],
webp: [0, 6]
}

function parseEffort(effort: string, format: string) {
Expand Down

0 comments on commit 5dce66b

Please sign in to comment.