Skip to content

Commit c511a19

Browse files
authored
feat: add sharp trim feature
2 parents 7d3bc6a + 6eac25f commit c511a19

File tree

4 files changed

+10
-0
lines changed

4 files changed

+10
-0
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ Currently the following transformations can be applied to images:
264264
| format | `f` | Output image format. Valid values: every valid [sharp output format string](https://sharp.pixelplumbing.com/api-output#toformat), i.e. `jpeg`, `gif`, `webp` or `raw`. |
265265
| progressive | `p` | Only available for jpeg and png formats. Enable progressive scan by passing `true`. |
266266
| crop | `c` | Setting crop to `true` enables the [sharp cropping feature](https://sharp.pixelplumbing.com/api-resize#crop). Note: Both `width` and `height` params are neccessary for crop to work. Default is `false`. |
267+
| trim | `t` | Setting trim to `true` enables the [sharp trim feature](https://sharp.pixelplumbing.com/api-resize#trim). |
267268
| gravity | `g` | When the crop option is activated you can specify the gravity of the cropping. Possible attributes of the optional `gravity` are `north`, `northeast`, `east`, `southeast`, `south`, `southwest`, `west`, `northwest`, `center` and `centre`. Default is `center`. |
268269
269270
# License

Diff for: src/interfaces.ts

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ export enum QueryParams {
2828
format = 'f',
2929
progressive = 'p',
3030
crop = 'c',
31+
trim = 't',
3132
gravity = 'g',
3233
}
3334

Diff for: src/resize.dto.ts

+4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export class ResizeDto {
5454
@IsBoolean()
5555
public crop: boolean = false
5656

57+
@Transform((value) => value === 'true')
58+
@IsBoolean()
59+
public trim: boolean = false
60+
5761
@IsIn([
5862
'north',
5963
'northeast',

Diff for: src/transformer.service.ts

+4
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ export class Transformer {
7676
options.format = (await transformer.metadata()).format as format
7777
}
7878

79+
if (options.trim) {
80+
transformer.trim()
81+
}
82+
7983
if (options.crop) {
8084
const [cropWidth, cropHeight] = this.getCropDimensions(
8185
this.cropMaxSize,

0 commit comments

Comments
 (0)