Skip to content

Commit

Permalink
feat(handlers): support kernel modifier (#143)
Browse files Browse the repository at this point in the history
  • Loading branch information
kyranet authored Sep 5, 2023
1 parent a008152 commit 9ed2708
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ Resize to `200x200px` using `embed` method and change format to `webp`:
| width / w | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/width_200/buffalo.png` |
| height / h | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/height_200/buffalo.png` |
| resize / s | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/s_200x200/buffalo.png` |
| kernel | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/s_200x200,kernel_nearest/buffalo.png` | Supported kernel: `nearest`, `cubic`, `mitchell`, `lanczos2` and `lanczos3` (default). |
| fit | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/s_200x200,fit_outside/buffalo.png` | Sets `fit` option for `resize`. |
| position / pos | [Docs](https://sharp.pixelplumbing.com/api-resize#resize) | `/s_200x200,pos_top/buffalo.png` | Sets `position` option for `resize`. |
| trim | [Docs](https://sharp.pixelplumbing.com/api-resize#trim) | `/trim_100/buffalo.png` |
Expand Down
8 changes: 8 additions & 0 deletions src/handlers/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,13 @@ export const enlarge: Handler = {
},
};

export const kernel: Handler = {
args: [VArgument],
apply: (context, _pipe, kernel) => {
context.kernel = kernel;
},
};

export const width: Handler = {
args: [VArgument],
apply: (context, pipe, width) => {
Expand Down Expand Up @@ -99,6 +106,7 @@ export const resize: Handler = {
fit: context.fit,
position: context.position,
background: context.background,
kernel: context.kernel,
});
},
};
Expand Down
3 changes: 2 additions & 1 deletion src/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { Sharp, Color } from "sharp";
import type { Sharp, Color, KernelEnum } from "sharp";

// TODO: Move to image-meta
export interface ImageMeta {
Expand Down Expand Up @@ -27,6 +27,7 @@ export interface HandlerContext {
position?: number | string;
background?: Color;
enlarge?: boolean;
kernel?: keyof KernelEnum;
meta: ImageMeta;
}

Expand Down

0 comments on commit 9ed2708

Please sign in to comment.