Skip to content

Commit a661d5a

Browse files
authored
feat: quality option, image transformation (#145)
1 parent 877994a commit a661d5a

File tree

4 files changed

+13
-3
lines changed

4 files changed

+13
-3
lines changed

infra/storage/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
FROM supabase/storage-api:v0.27.1
1+
FROM supabase/storage-api:v0.28.0
22

33
RUN apk add curl --no-cache

src/lib/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ export interface TransformOptions {
8989
* Fill resizes the image to fill the entire width and height. If the object's aspect ratio does not match the width and height, the image will be stretched to fit.
9090
*/
9191
resize?: 'cover' | 'contain' | 'fill'
92+
/**
93+
* Set the quality of the returned image, this is percentage based, default 80
94+
*/
95+
quality?: number
9296
/**
9397
* Specify the format of the image requested.
9498
*

src/packages/StorageFileApi.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,10 @@ export default class StorageFileApi {
597597
params.push(`format=${transform.format}`)
598598
}
599599

600+
if (transform.quality) {
601+
params.push(`quality=${transform.quality}`)
602+
}
603+
600604
return params.join('&')
601605
}
602606
}

test/storageFileApi.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,11 @@ describe('Object API', () => {
221221
transform: {
222222
width: 200,
223223
height: 300,
224+
quality: 70,
224225
},
225226
})
226227
expect(res.data.publicUrl).toEqual(
227-
`${URL}/render/image/public/${bucketName}/${uploadPath}?width=200&height=300`
228+
`${URL}/render/image/public/${bucketName}/${uploadPath}?width=200&height=300&quality=70`
228229
)
229230
})
230231

@@ -295,6 +296,7 @@ describe('Object API', () => {
295296
transform: {
296297
width: 200,
297298
height: 200,
299+
quality: 60,
298300
},
299301
})
300302

@@ -306,7 +308,7 @@ describe('Object API', () => {
306308
expect(parseInt(imageResp.headers.get('content-length') || '')).toBeGreaterThan(0)
307309
expect(imageResp.status).toEqual(200)
308310
expect(imageResp.headers.get('x-transformations')).toEqual(
309-
'height:200,width:200,resizing_type:fill'
311+
'height:200,width:200,resizing_type:fill,quality:60'
310312
)
311313
})
312314
})

0 commit comments

Comments
 (0)