Skip to content

Commit dfebe9f

Browse files
authored
Merge pull request #89 from imagekit-developer/SDK-94
added parameters
2 parents 7bc4d88 + 54035b3 commit dfebe9f

File tree

17 files changed

+476
-217
lines changed

17 files changed

+476
-217
lines changed

.github/workflows/nodejs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99

1010
strategy:
1111
matrix:
12-
node-version: [10.x, 12.x, 14.x, 16.x, 18.x]
12+
node-version: [12.x, 14.x, 16.x, 18.x]
1313

1414
steps:
1515
- uses: actions/checkout@v1

.github/workflows/npmpublish.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212

1313
strategy:
1414
matrix:
15-
node-version: [10.x, 12.x, 14.x]
15+
node-version: [12.x, 14.x]
1616

1717
steps:
1818
- uses: actions/checkout@v1

README.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ Node.js SDK for [ImageKit](https://imagekit.io/) implements the new APIs and int
1414
ImageKit is complete media storage, optimization, and transformation solution that comes with an [image and video CDN](https://imagekit.io/features/imagekit-infrastructure). It can be integrated with your existing infrastructure - storage like AWS S3, web servers, your CDN, and custom domain names, allowing you to deliver optimized images in minutes with minimal code changes.
1515

1616
##### Table of contents
17+
* [Changelog](#changelog)
1718
* [Installation](#installation)
1819
* [Initialization](#initialization)
1920
* [URL generation](#url-generation)
@@ -24,6 +25,19 @@ ImageKit is complete media storage, optimization, and transformation solution th
2425
* [Support](#support)
2526
* [Links](#links)
2627

28+
## Changelog
29+
30+
### SDK Version 5.0.0
31+
32+
#### Breaking changes
33+
34+
**1. Overlay syntax update**
35+
* In version 5.0.0, we've removed the old overlay syntax parameters for transformations, such as `oi`, `ot`, `obg`, and [more](https://docs.imagekit.io/features/image-transformations/overlay). These parameters are deprecated and will start returning errors when used in URLs. Please migrate to the new layers syntax that supports overlay nesting, provides better positional control, and allows more transformations at the layer level. You can start with [examples](https://docs.imagekit.io/features/image-transformations/overlay-using-layers#examples) to learn quickly.
36+
* You can migrate to the new layers syntax using the `raw` transformation parameter.
37+
38+
**2. Remove Node.js 10.x support**
39+
* In version 5.0.0, we've removed support for Node.js version 10.x.
40+
2741
## Installation
2842

2943
Use the following command to download this module. Use the optional `--save` parameter if you wish to save the dependency in your `package.json` file.
@@ -242,6 +256,29 @@ var imageURL = imagekit.url({
242256
https://ik.imagekit.io/your_imagekit_id/tr:h-300,w-400,l-image,i-ik_canvas,bg-FF0000,w-300,h-100,l-end/img/sample-video.mp4
243257
```
244258

259+
**5. Arithmetic expressions in transformations**
260+
261+
ImageKit allows use of [arithmetic expressions](https://docs.imagekit.io/features/arithmetic-expressions-in-transformations) in certain dimension and position-related parameters, making media transformations more flexible and dynamic.
262+
263+
For example:
264+
265+
```js
266+
var imageURL = imagekit.url({
267+
src: "https://ik.imagekit.io/your_imagekit_id/default-image.jpg",
268+
transformation: [{
269+
"width": "iw_div_4",
270+
"height": "ih_div_2",
271+
"border": "cw_mul_0.05_yellow"
272+
}]
273+
});
274+
```
275+
276+
**Sample Result URL**
277+
```
278+
https://ik.imagekit.io/your_imagekit_id/tr:w-iw_div_4,h-ih_div_2,b-cw_mul_0.05_yellow/default-image.jpg
279+
```
280+
281+
245282
#### List of supported transformations
246283

247284
See the complete list of transformations supported in ImageKit [here](https://docs.imagekit.io/features/image-transformations). The SDK gives a name to each transformation parameter e.g. `height` for `h` and `width` for `w` parameter. It makes your code more readable. If the property does not match any of the following supported options, it is added as it is.
@@ -278,6 +315,8 @@ If you want to generate transformations in your application and add them to the
278315
| effectUSM | e-usm |
279316
| effectContrast | e-contrast |
280317
| effectGray | e-grayscale |
318+
| effectShadow | e-shadow |
319+
| effectGradient | e-gradient |
281320
| original | orig |
282321
| raw | `replaced by the parameter value` |
283322

libs/constants/errorMessages.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,7 @@ export default {
4747
"VERIFY_WEBHOOK_EVENT_SIGNATURE_MISSING": { message: "Signature missing", help: "Please pass x-ik-signature header as utf8 string" },
4848
"VERIFY_WEBHOOK_EVENT_TIMESTAMP_MISSING": { message: "Timestamp missing", help: "Please pass x-ik-signature header as utf8 string" },
4949
"VERIFY_WEBHOOK_EVENT_TIMESTAMP_INVALID": { message: "Timestamp invalid", help: "Please pass x-ik-signature header as utf8 string" },
50+
"INVALID_TRANSFORMATION": { message: "Invalid transformation parameter. Please include at least pre, post, or both.", help: ""},
51+
"INVALID_PRE_TRANSFORMATION": { message: "Invalid pre transformation parameter.", help: ""},
52+
"INVALID_POST_TRANSFORMATION": { message: "Invalid post transformation parameter.", help: ""},
5053
};

libs/constants/supportedTransforms.ts

Lines changed: 10 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -87,144 +87,6 @@ const supportedTransforms = {
8787
*/
8888
named: "n",
8989

90-
/**
91-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-image-oi}
92-
*/
93-
overlayImage: "oi",
94-
95-
/**
96-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-image-aspect-ratio-oiar}
97-
*/
98-
overlayImageAspectRatio: "oiar",
99-
100-
/**
101-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-image-background-oibg}
102-
*/
103-
overlayImageBackground: "oibg",
104-
105-
/**
106-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-image-border-oib}
107-
*/
108-
overlayImageBorder: "oib",
109-
110-
/**
111-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-image-dpr-oidpr}
112-
*/
113-
overlayImageDPR: "oidpr",
114-
115-
/**
116-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-image-quality-oiq}
117-
*/
118-
overlayImageQuality: "oiq",
119-
120-
/**
121-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-image-cropping}
122-
*/
123-
overlayImageCropping: "oic",
124-
/**
125-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#oifo}
126-
*/
127-
overlayImageFocus: "oifo",
128-
/**
129-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#trimming-of-the-overlay-image}
130-
*/
131-
overlayImageTrim: "oit",
132-
133-
/**
134-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-x-position-ox}
135-
*/
136-
overlayX: "ox",
137-
138-
/**
139-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-y-position-oy}
140-
*/
141-
overlayY: "oy",
142-
143-
/**
144-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-focus-ofo}
145-
*/
146-
overlayFocus: "ofo",
147-
148-
/**
149-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-height-oh}
150-
*/
151-
overlayHeight: "oh",
152-
153-
/**
154-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-width-ow}
155-
*/
156-
overlayWidth: "ow",
157-
158-
/**
159-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-text-ot}
160-
*/
161-
overlayText: "ot",
162-
163-
/**
164-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-text-size-ots}
165-
*/
166-
overlayTextFontSize: "ots",
167-
168-
/**
169-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-text-font-otf}
170-
*/
171-
overlayTextFontFamily: "otf",
172-
173-
/**
174-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-text-color-otc}
175-
*/
176-
overlayTextColor: "otc",
177-
178-
/**
179-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-transparency-oa}
180-
*/
181-
overlayTextTransparency: "oa",
182-
183-
/**
184-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-transparency-oa}
185-
*/
186-
overlayAlpha: "oa",
187-
188-
/**
189-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-text-typography-ott}
190-
*/
191-
overlayTextTypography: "ott",
192-
193-
/**
194-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-background-obg}
195-
*/
196-
overlayBackground: "obg",
197-
198-
/**
199-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-text-encoded-ote}
200-
*/
201-
overlayTextEncoded: "ote",
202-
203-
/**
204-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-text-width-otw}
205-
*/
206-
overlayTextWidth: "otw",
207-
208-
/**
209-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-text-background-otbg}
210-
*/
211-
overlayTextBackground: "otbg",
212-
213-
/**
214-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-text-padding-otp}
215-
*/
216-
overlayTextPadding: "otp",
217-
218-
/**
219-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-text-inner-alignment-otia}
220-
*/
221-
overlayTextInnerAlignment: "otia",
222-
223-
/**
224-
* @see {@link https://docs.imagekit.io/features/image-transformations/overlay#overlay-radius-or}
225-
*/
226-
overlayRadius: "or",
227-
22890
/**
22991
* @see {@link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#progressive-image-pr}
23092
*/
@@ -280,6 +142,16 @@ const supportedTransforms = {
280142
*/
281143
effectGray: "e-grayscale",
282144

145+
/**
146+
* @link https://docs.imagekit.io/features/image-transformations/image-enhancement-and-color-manipulation#shadow-e-shadow
147+
*/
148+
effectShadow: "e-shadow",
149+
150+
/**
151+
* @link https://docs.imagekit.io/features/image-transformations/image-enhancement-and-color-manipulation#gradient-e-gradient
152+
*/
153+
effectGradient: "e-gradient",
154+
283155
/**
284156
* @see {@link https://docs.imagekit.io/features/image-transformations/resize-crop-and-other-transformations#original-image-orig}
285157
*/

libs/interfaces/FileDetails.ts

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,46 @@
11
import { FileType } from "./FileType";
22
import { Item } from "./Item";
33

4+
export interface EmbeddedMetadataValues {
5+
[key: string]:
6+
| string
7+
| number
8+
| boolean
9+
| Date
10+
| Array<string | number | boolean | Date>
11+
}
12+
13+
export interface AITagItem {
14+
name: string
15+
confidence: number
16+
source: 'google-auto-tagging' | 'aws-auto-tagging'
17+
}
18+
19+
export interface CMValues {
20+
[key: string]: | string
21+
| number
22+
| boolean
23+
| Array<string | number | boolean>
24+
}
25+
26+
interface BgRemoval {
27+
name: string
28+
options: {
29+
bg_color?: string
30+
bg_image_url?: string
31+
add_shadow: boolean
32+
semitransparency: boolean
33+
}
34+
}
35+
36+
interface AutoTag {
37+
name: string
38+
maxTags: number
39+
minConfidence: number
40+
}
41+
42+
export type Extension = (BgRemoval | AutoTag)[];
43+
444
/**
545
* Options when updating file details such as tags and customCoordinates attribute using update file detail API.
646
*
@@ -19,7 +59,7 @@ export interface FileDetailsOptions {
1959
/*
2060
* Object with array of extensions to be processed on the image.
2161
*/
22-
extensions?: object[];
62+
extensions?: Extension;
2363
/*
2464
* Final status of pending extensions will be sent to this URL.
2565
*/
@@ -31,7 +71,7 @@ export interface FileDetailsOptions {
3171
/*
3272
* A key-value data to be associated with the asset. To unset a key, send null value for that key. Before setting any custom metadata on an asset you have to create the field using custom metadata fields API.
3373
*/
34-
customMetadata?: object;
74+
customMetadata?: CMValues;
3575
}
3676

3777
/**
@@ -86,19 +126,19 @@ export interface FileObject {
86126
/*
87127
* AITags field is populated only because the google-auto-tagging extension was executed synchronously and it received a successresponse.
88128
*/
89-
AITags?: object[];
129+
AITags?: AITagItem[];
90130
/*
91131
* Field object which will contain the status of each extension at the time of completion of the update/upload request.
92132
*/
93133
extensionStatus?: { [key: string]: string }
94134
/*
95135
* Consolidated embedded metadata associated with the file. It includes exif, iptc, and xmp data.
96136
*/
97-
embeddedMetadata?: object | null;
137+
embeddedMetadata?: EmbeddedMetadataValues | null;
98138
/*
99139
* A key-value data associated with the asset. Before setting any custom metadata on an asset, you have to create the field using custom metadata fields API.
100140
*/
101-
customMetadata?: object;
141+
customMetadata?: CMValues;
102142
/*
103143
* Size of the file in bytes
104144
*/
@@ -130,7 +170,7 @@ export interface FileObject {
130170
/**
131171
* An object containing the file or file version's id (versionId) and name.
132172
*/
133-
versionInfo?: object;
173+
versionInfo?: { name: string; id: string };
134174
}
135175

136176

libs/interfaces/UploadOptions.ts

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
import { ReadStream } from "fs";
2+
import { Extension } from "./FileDetails";
3+
4+
interface TransformationObject {
5+
type: "transformation";
6+
value: string;
7+
}
8+
interface GifToVideoOrThumbnailObject {
9+
type: "gif-to-video" | "thumbnail";
10+
value?: string;
11+
}
12+
13+
interface AbsObject {
14+
type: "abs";
15+
value: string;
16+
protocol: "hls" | "dash";
17+
}
18+
19+
type PostTransformation = TransformationObject | GifToVideoOrThumbnailObject | AbsObject;
20+
21+
interface Transformation{
22+
pre?: string
23+
post?: PostTransformation[]
24+
}
225

326
/**
427
* Options used when uploading a file
@@ -72,7 +95,7 @@ export interface UploadOptions {
7295
/*
7396
* Object with array of extensions to be processed on the image.
7497
*/
75-
extensions?: object[];
98+
extensions?: Extension;
7699
/*
77100
* Final status of pending extensions will be sent to this URL.
78101
*/
@@ -83,5 +106,6 @@ export interface UploadOptions {
83106
overwriteCustomMetadata?: boolean;
84107
customMetadata?: {
85108
[key: string]: string | number | boolean | Array<string | number | boolean>;
86-
}
109+
},
110+
transformation?: Transformation
87111
}

0 commit comments

Comments
 (0)