Skip to content

Commit f9007a2

Browse files
committed
add test cases
1 parent 0d105fb commit f9007a2

File tree

5 files changed

+329
-76
lines changed

5 files changed

+329
-76
lines changed

README.md

Lines changed: 58 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ https://ik.imagekit.io/your_imagekit_id/endpoint/default-image.jpg?tr=h-300%2Cw-
150150

151151
The `.url()` method accepts the following parameters
152152

153-
| Option | Description |
154-
| :----------------| :----------------------------- |
155-
| urlEndpoint | Optional. The base URL to be appended before the path of the image. If not specified, the URL Endpoint specified at the time of SDK initialization is used. For example, https://ik.imagekit.io/your_imagekit_id/endpoint/ |
156-
| path | Conditional. This is the path at which the image exists. For example, `/path/to/image.jpg`. Either the `path` or `src` parameter needs to be specified for URL generation. |
157-
| src | Conditional. This is the complete URL of an image already mapped to ImageKit. For example, `https://ik.imagekit.io/your_imagekit_id/endpoint/path/to/image.jpg`. Either the `path` or `src` parameter needs to be specified for URL generation. |
158-
| transformation | Optional. An array of objects specifying the transformation to be applied in the URL. The transformation name and the value should be specified as a key-value pair in the object. Different steps of a [chained transformation](https://docs.imagekit.io/features/image-transformations/chained-transformations) can be specified as different objects of the array. The complete list of supported transformations in the SDK and some examples of using them are given later. If you use a transformation name that is not specified in the SDK, it gets applied as it is in the URL. |
159-
| transformationPostion | Optional. The default value is `path`, which places the transformation string as a path parameter in the URL. It can also be specified as `query`, which adds the transformation string as the query parameter `tr` in the URL. If you use the `src` parameter to create the URL, then the transformation string is always added as a query parameter. |
160-
| queryParameters | Optional. These are the other query parameters that you want to add to the final URL. These can be any query parameters and are not necessarily related to ImageKit. Especially useful if you want to add some versioning parameters to your URLs. |
153+
| Option | Description |
154+
| :-------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
155+
| urlEndpoint | Optional. The base URL to be appended before the path of the image. If not specified, the URL Endpoint specified at the time of SDK initialization is used. For example, https://ik.imagekit.io/your_imagekit_id/endpoint/ |
156+
| path | Conditional. This is the path at which the image exists. For example, `/path/to/image.jpg`. Either the `path` or `src` parameter needs to be specified for URL generation. |
157+
| src | Conditional. This is the complete URL of an image already mapped to ImageKit. For example, `https://ik.imagekit.io/your_imagekit_id/endpoint/path/to/image.jpg`. Either the `path` or `src` parameter needs to be specified for URL generation. |
158+
| transformation | Optional. An array of objects specifying the transformation to be applied in the URL. The transformation name and the value should be specified as a key-value pair in the object. Different steps of a [chained transformation](https://docs.imagekit.io/features/image-transformations/chained-transformations) can be specified as different objects of the array. The complete list of supported transformations in the SDK and some examples of using them are given later. If you use a transformation name that is not specified in the SDK, it gets applied as it is in the URL. |
159+
| transformationPostion | Optional. The default value is `path`, which places the transformation string as a path parameter in the URL. It can also be specified as `query`, which adds the transformation string as the query parameter `tr` in the URL. If you use the `src` parameter to create the URL, then the transformation string is always added as a query parameter. |
160+
| queryParameters | Optional. These are the other query parameters that you want to add to the final URL. These can be any query parameters and are not necessarily related to ImageKit. Especially useful if you want to add some versioning parameters to your URLs. |
161161

162162
#### Examples of generating URLs
163163

@@ -294,40 +294,55 @@ See the complete list of transformations supported in ImageKit [here](https://do
294294

295295
If you want to generate transformations in your application and add them to the URL as it is, use the `raw` parameter.
296296

297-
| Supported Transformation Name | Translates to parameter |
298-
|-------------------------------|-------------------------|
299-
| height | h |
300-
| width | w |
301-
| aspectRatio | ar |
302-
| quality | q |
303-
| crop | c |
304-
| cropMode | cm |
305-
| x | x |
306-
| y | y |
307-
| focus | fo |
308-
| format | f |
309-
| radius | r |
310-
| background | bg |
311-
| border | b |
312-
| rotation | rt |
313-
| blur | bl |
314-
| named | n |
315-
| progressive | pr |
316-
| lossless | lo |
317-
| trim | t |
318-
| metadata | md |
319-
| colorProfile | cp |
320-
| defaultImage | di |
321-
| dpr | dpr |
322-
| effectSharpen | e-sharpen |
323-
| effectUSM | e-usm |
324-
| effectContrast | e-contrast |
325-
| effectGray | e-grayscale |
326-
| effectShadow | e-shadow |
327-
| effectGradient | e-gradient |
328-
| original | orig |
329-
| raw | The string provided in raw will be added in the URL as it is. |
330-
297+
| Supported Transformation Name | Translates to parameter |
298+
| ----------------------------- | ------------------------------------------------------------- |
299+
| width | w |
300+
| height | h |
301+
| aspectRatio | ar |
302+
| quality | q |
303+
| aiRemoveBackground | e-bgremove (ImageKit powered) |
304+
| aiRemoveBackgroundExternal | e-removedotbg (Using third party) |
305+
| aiUpscale | e-upscale |
306+
| aiRetouch | e-retouch |
307+
| aiVariation | e-genvar |
308+
| aiDropShadow | e-dropshadow |
309+
| aiChangeBackground | e-changebg |
310+
| crop | c |
311+
| cropMode | cm |
312+
| x | x |
313+
| y | y |
314+
| focus | fo |
315+
| format | f |
316+
| radius | r |
317+
| background | bg |
318+
| border | b |
319+
| rotation | rt |
320+
| blur | bl |
321+
| named | n |
322+
| dpr | dpr |
323+
| progressive | pr |
324+
| lossless | lo |
325+
| trim | t |
326+
| metadata | md |
327+
| colorProfile | cp |
328+
| defaultImage | di |
329+
| original | orig |
330+
| videoCodec | vc |
331+
| audioCodec | ac |
332+
| grayscale | e-grayscale |
333+
| contrastStretch | e-contrast |
334+
| shadow | e-shadow |
335+
| sharpen | e-sharpen |
336+
| unsharpMask | e-usm |
337+
| gradient | e-gradient |
338+
| opacity | o |
339+
| zoom | z |
340+
| page | pg |
341+
| startOffset | so |
342+
| endOffset | eo |
343+
| duration | du |
344+
| streamingResolutions | sr |
345+
| raw | The string provided in raw will be added in the URL as it is. |
331346

332347
### File Upload
333348

@@ -512,4 +527,4 @@ try {
512527
// {'content-type': 'application/json', 'x-request-id': 'ee560df4-d44f-455e-a48e-29dfda49aec5'}
513528
console.log(response.$ResponseMetadata.headers);
514529
}
515-
```
530+
```

src/constants/supportedTransforms.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,13 @@ export const supportedTransforms: { [key: string]: string } = {
4343

4444
// AI & advanced effects
4545
grayscale: "e-grayscale",
46-
aiBGRemoveExternal: "e-removedotbg",
4746
aiUpscale: "e-upscale",
4847
aiRetouch: "e-retouch",
4948
aiVariation: "e-genvar",
5049
aiDropShadow: "e-dropshadow",
5150
aiChangeBackground: "e-changebg",
5251
aiRemoveBackground: "e-bgremove",
52+
aiRemoveBackgroundExternal: "e-removedotbg",
5353
contrastStretch: "e-contrast",
5454
shadow: "e-shadow",
5555
sharpen: "e-sharpen",

src/interfaces/Transformation.ts

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
export type TransformationPosition = "path" | "query";
22

3+
type StreamingResolution = "240" | "360" | "480" | "720" | "1080" | "1440" | "2160";
4+
35
/**
46
* The SDK provides easy to use names for transformations. These names are converted to the corresponding transformation string before being added to the URL.
57
* SDKs are updated regularly to support new transformations. If you want to use a transformation that is not supported by the SDK, you can use the `raw` parameter to pass the transformation string directly.
@@ -110,26 +112,29 @@ export interface Transformation {
110112
yCenter?: number | string;
111113

112114
/**
113-
* Output format for images or videos, e.g., `"jpg"`, `"png"`, `"webp"`, `"mp4"`, `"auto"`.
114-
* ImageKit will automatically determine the format based on device support even if you do not specify it.
115+
* Output format for images or videos, e.g., `"jpg"`, `"png"`, `"webp"`, `"mp4"`, `"auto"`. You can also pass `orig` which works only for images and will return the image in the original format.
116+
*
117+
* ImageKit will automatically deliver images and videos in best possible format based on the device support unless you disable it from the dashboard settings or override it using the `format` parameter.
115118
*
116119
* {@link https://imagekit.io/docs/image-optimization#format---f}
120+
*
121+
* {@link https://imagekit.io/docs/video-optimization#format---f}}
117122
*/
118-
format?: string;
123+
format?: "auto" | "webp" | "jpg" | "jpeg" | "png" | "gif" | "svg" | "mp4" | "webm" | "avif" | "orig";
119124

120125
/**
121-
* Video codec, e.g., `"h264"`, `"vp9"`, `"av1"`.
126+
* Video codec, e.g., `"h264"`, `"vp9"`, `"av1"` or `"none"`.
122127
*
123128
* {@link https://imagekit.io/docs/video-optimization#video-codec---vc}
124129
*/
125-
videoCodec?: string;
130+
videoCodec?: "h264" | "vp9" | "av1" | "none";
126131

127132
/**
128-
* Audio codec, e.g., `"aac"`, `"opus"`.
133+
* Audio codec, e.g., `"aac"`, `"opus"` or `"none"`.
129134
*
130135
* {@link https://imagekit.io/docs/video-optimization#audio-codec---ac}
131136
*/
132-
audioCodec?: string;
137+
audioCodec?: "aac" | "opus" | "none";
133138

134139
/**
135140
* Corner radius for rounded corners (e.g., `20`) or `"max"` for circular/oval shapes.
@@ -208,12 +213,11 @@ export interface Transformation {
208213
duration?: number | string;
209214

210215
/**
211-
* Resolutions for adaptive bitrate streaming (videos).
212-
* e.g., `240_360_480_720_1080` will generate 5 representations and manifest.
216+
* Provide an array of resolutions (e.g. `["240", "360", "480", "720", "1080"]`).
213217
*
214218
* {@link https://imagekit.io/docs/adaptive-bitrate-streaming}
215219
*/
216-
streamingResolutions?: string;
220+
streamingResolutions?: StreamingResolution[];
217221

218222
/**
219223
* Enable grayscale effect for images.
@@ -222,13 +226,6 @@ export interface Transformation {
222226
*/
223227
grayscale?: true;
224228

225-
/**
226-
* Use third-party background removal. Use `removeBackground` - ImageKit's in-house background removal which is 90% cheaper.
227-
*
228-
* {@link https://imagekit.io/docs/ai-transformations#background-removal-e-removedotbg}
229-
*/
230-
aiBGRemoveExternal?: true
231-
232229
/**
233230
* Upscale images beyond their original dimensions with AI.
234231
*
@@ -252,11 +249,13 @@ export interface Transformation {
252249

253250
/**
254251
* Add an AI-based drop shadow around a foreground object on a transparent or removed background.
255-
* You can control the direction, elevation, and saturation of the light source. E.g. change light direction `az-45`.
252+
* Optionally, you can control the direction, elevation, and saturation of the light source. E.g. change light direction `az-45`.
253+
*
254+
* Pass `true` for default drop shadow or a string for custom drop shadow.
256255
*
257256
* {@link https://imagekit.io/docs/ai-transformations#ai-drop-shadow-e-dropshadow}
258257
*/
259-
aiDropShadow?: string
258+
aiDropShadow?: true | string
260259

261260
/**
262261
* Change background using AI. Provide a prompt or base64-encoded prompt. e.g. `prompt-snow road` or `prompte-[urlencoded_base64_encoded_text]`.
@@ -272,6 +271,13 @@ export interface Transformation {
272271
*/
273272
aiRemoveBackground?: true
274273

274+
/**
275+
* Use third-party background removal. Use `aiRemoveBackground` - ImageKit's in-house background removal which is 90% cheaper.
276+
*
277+
* {@link https://imagekit.io/docs/ai-transformations#background-removal-e-removedotbg}
278+
*/
279+
aiRemoveBackgroundExternal?: true
280+
275281
/**
276282
* Auto-enhance contrast for an image (contrast stretch).
277283
*
@@ -282,30 +288,38 @@ export interface Transformation {
282288
/**
283289
* This adds a shadow under solid objects in an input image with a transparent background. Check `eDropshadow` for AI-based shadows.
284290
*
291+
* Pass `true` for default shadow or a string for custom shadow.
292+
*
285293
* {@link https://imagekit.io/docs/effects-and-enhancements#shadow---e-shadow}
286294
*/
287-
shadow?: string
295+
shadow?: true | string
288296

289297
/**
290298
* It is used to sharpen the input image. It is useful when highlighting the edges and finer details within an image.
291299
*
300+
* Pass `true` for default sharpening or a number for custom sharpening.
301+
*
292302
* {@link https://imagekit.io/docs/effects-and-enhancements#sharpen---e-sharpen}
293303
*/
294304
sharpen?: true | number
295305

296306
/**
297307
* Unsharp Masking (USM) is an image sharpening technique. This transform allows you to apply and control unsharp masks on your images.
298308
*
309+
* Pass `true` for default unsharp mask or a string for custom unsharp mask.
310+
*
299311
* {@link https://imagekit.io/docs/effects-and-enhancements#unsharp-mask---e-usm}
300312
*/
301-
unsharpMask?: string;
313+
unsharpMask?: true | string;
302314

303315
/**
304316
* The gradient formed is a linear gradient containing two colors, and it can be customized.
305317
*
318+
* Pass `true` for default gradient or a string for custom gradient.
319+
*
306320
* {@link https://imagekit.io/docs/effects-and-enhancements#gradient---e-gradient}
307321
*/
308-
gradient?: string;
322+
gradient?: true | string;
309323

310324
/**
311325
* Used to specify whether the output JPEG image must be rendered progressively. In progressive loading, the output image renders as a low-quality pixelated full image, which, over time, keeps on adding more pixels and information to the image. This helps you maintain a fast perceived load time.

0 commit comments

Comments
 (0)