Skip to content

Commit

Permalink
feat: image transformation (#128) (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
inian committed Dec 13, 2022
1 parent 01fc19b commit a92d34a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
12 changes: 12 additions & 0 deletions src/lib/types.ts
Expand Up @@ -74,7 +74,19 @@ export interface Metadata {
}

export interface TransformOptions {
/**
* The width of the image in pixels.
*/
width?: number
/**
* The height of the image in pixels.
*/
height?: number
/**
* The resize mode can be cover, contain or fill. Defaults to cover.
* Cover resizes the image to maintain it's aspect ratio while filling the entire width and height.
* Contain resizes the image to maintain it's aspect ratio while fitting the entire image within the width and height.
* 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.
*/
resize?: 'cover' | 'contain' | 'fill'
}
8 changes: 4 additions & 4 deletions src/packages/StorageFileApi.ts
Expand Up @@ -265,7 +265,7 @@ export default class StorageFileApi {
* @param path The file path, including the current file name. For example `folder/image.png`.
* @param expiresIn The number of seconds until the signed URL expires. For example, `60` for a URL which is valid for one minute.
* @param options.download triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
* @param options.transform The visiting client will receive the transformed variant of the image by providing transform options
* @param options.transform Transform the asset before serving it to the client.
*/
async createSignedUrl(
path: string,
Expand Down Expand Up @@ -359,7 +359,7 @@ export default class StorageFileApi {
* Downloads a file.
*
* @param path The full path and file name of the file to be downloaded. For example `folder/image.png`.
* @param options.download download a transformed image
* @param options.transform Transform the asset before serving it to the client.
*/
async download(
path: string,
Expand Down Expand Up @@ -401,8 +401,8 @@ export default class StorageFileApi {
* This function does not verify if the bucket is public. If a public URL is created for a bucket which is not public, you will not be able to download the asset.
*
* @param path The path and name of the file to generate the public URL for. For example `folder/image.png`.
* @param options.download triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
* @param options.transform adds image transformations parameters to the generated url
* @param options.download Triggers the file as a download if set to true. Set this parameter as the name of the file if you want to trigger the download with a different filename.
* @param options.transform Transform the asset before serving it to the client.
*/
getPublicUrl(
path: string,
Expand Down

0 comments on commit a92d34a

Please sign in to comment.