Skip to content

Commit b8daae0

Browse files
ANKUR DWIVEDIANKUR DWIVEDI
authored andcommitted
added transformation effectShadow and effect
1 parent 1c2eed5 commit b8daae0

File tree

6 files changed

+70
-185
lines changed

6 files changed

+70
-185
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ If you want to generate transformations in your application and add them to the
296296
| effectUSM | e-usm |
297297
| effectContrast | e-contrast |
298298
| effectGray | e-grayscale |
299+
| effectShadow | e-shadow |
300+
| effectGradient | e-gradient |
299301
| original | orig |
300302
| raw | The string provided in raw will be added in the URL as it is. |
301303

src/constants/supportedTransforms.ts

Lines changed: 10 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -87,141 +87,6 @@ const supportedTransforms: { [key: string]: string } = {
8787
*/
8888
named: "n",
8989

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

150+
/**
151+
* @link https://docs.imagekit.io/features/image-transformations/image-enhancement-and-color-manipulation#shadow-e-shadow
152+
*/
153+
effectShadow: "e-shadow",
154+
155+
/**
156+
* @link https://docs.imagekit.io/features/image-transformations/image-enhancement-and-color-manipulation.md#gradient-e-gradient
157+
*/
158+
effectGradient: "e-gradient",
159+
285160
/**
286161
* @link https://docs.imagekit.io/features/image-transformations/conditional-transformations
287162
*/

src/interfaces/UploadOptions.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
interface postTransformation{
2+
type: 'abs' | 'thumbnail' | 'transformation' | 'gif-to-video'
3+
protocol?: 'hls' | 'dash'
4+
value?: string
5+
}
6+
interface transformation{
7+
pre?: string
8+
post?: postTransformation[]
9+
}
110
/**
211
* Options used when uploading a file
312
*
@@ -113,6 +122,8 @@ export interface UploadOptions {
113122
*/
114123
customMetadata?: string | Record<string, string | number | boolean | Array<string | number | boolean>>
115124

125+
transformation?: transformation
126+
116127
/**
117128
* Optional XMLHttpRequest object that you can send for upload API request. You can listen to `progress` and other events on this object for any custom logic.
118129
*/

src/upload/index.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,10 @@ export const upload = (
6060
} else if (key === "customMetadata" && typeof uploadOptions.customMetadata === "object" &&
6161
!Array.isArray(uploadOptions.customMetadata) && uploadOptions.customMetadata !== null) {
6262
formData.append('customMetadata', JSON.stringify(uploadOptions.customMetadata));
63-
} else if(uploadOptions[key] !== undefined) {
63+
} else if(key === "transformation" && typeof uploadOptions.transformation === "object" &&
64+
uploadOptions.transformation !== null) {
65+
formData.append(key, JSON.stringify(uploadOptions.transformation));
66+
}else if(uploadOptions[key] !== undefined) {
6467
formData.append(key, String(uploadOptions[key]));
6568
}
6669
}

test/upload.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,4 +1091,35 @@ describe("File upload", function () {
10911091
expect(callback.calledOnce).to.be.true;
10921092
sinon.assert.calledWith(callback, null, uploadSuccessResponseObj);
10931093
});
1094+
1095+
it('With pre and post transformation', async function () {
1096+
const fileOptions = {
1097+
...securityParameters,
1098+
fileName: "test_file_name",
1099+
file: "test_file",
1100+
responseFields: "tags, customCoordinates, isPrivateFile, metadata",
1101+
useUniqueFileName: false,
1102+
transformation: { pre: 'w-100', post: [{type: 'transformation', value: ''}]}
1103+
};
1104+
var callback = sinon.spy();
1105+
1106+
imagekit.upload(fileOptions, callback);
1107+
1108+
expect(server.requests.length).to.be.equal(1);
1109+
await sleep();
1110+
successUploadResponse();
1111+
await sleep();
1112+
1113+
var arg = server.requests[0].requestBody;
1114+
1115+
expect(arg.get('file')).to.be.equal("test_file");
1116+
expect(arg.get('fileName')).to.be.equal("test_file_name");
1117+
expect(arg.get('responseFields')).to.be.equal("tags, customCoordinates, isPrivateFile, metadata");
1118+
expect(arg.get('useUniqueFileName')).to.be.equal('false');
1119+
expect(arg.get('publicKey')).to.be.equal('test_public_key');
1120+
expect(arg.get('transformation')).to.be.equal(JSON.stringify(fileOptions.transformation));
1121+
1122+
expect(callback.calledOnce).to.be.true;
1123+
sinon.assert.calledWith(callback, null, uploadSuccessResponseObj);
1124+
});
10941125
});

test/url-generation.js

Lines changed: 12 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -182,43 +182,30 @@ describe("URL generation", function () {
182182
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300,w-400:rndm_trnsf-abcd/test_path.jpg`);
183183
});
184184

185-
it('overlayImage', function () {
185+
it('Overlay image', function () {
186186
const url = imagekit.url({
187187
path: "/test_path.jpg",
188188
transformation: [{
189189
"height": "300",
190190
"width": "400",
191-
overlayImage: "overlay.jpg"
191+
"raw": "l-image,i-overlay.jpg,w-100,b-10_CDDC39,l-end"
192192
}]
193193
})
194194

195-
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300,w-400,oi-overlay.jpg/test_path.jpg`);
195+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300,w-400,l-image,i-overlay.jpg,w-100,b-10_CDDC39,l-end/test_path.jpg`);
196196
});
197197

198-
it('overlayImage with slash in path', function () {
198+
it('Overlay image with slash in path', function () {
199199
const url = imagekit.url({
200200
path: "/test_path.jpg",
201201
transformation: [{
202202
"height": "300",
203203
"width": "400",
204-
overlayImage: "/path/to/overlay.jpg"
204+
"raw": "l-image,i-/path/to/overlay.jpg,w-100,b-10_CDDC39,l-end"
205205
}]
206206
})
207207

208-
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300,w-400,oi-path@@to@@overlay.jpg/test_path.jpg`);
209-
});
210-
211-
it('overlayX', function () {
212-
const url = imagekit.url({
213-
path: "/test_path.jpg",
214-
transformation: [{
215-
"height": "300",
216-
"width": "400",
217-
overlayX: 10
218-
}]
219-
})
220-
221-
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300,w-400,ox-10/test_path.jpg`);
208+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300,w-400,l-image,i-/path/to/overlay.jpg,w-100,b-10_CDDC39,l-end/test_path.jpg`);
222209
});
223210

224211
it('Border', function () {
@@ -234,7 +221,7 @@ describe("URL generation", function () {
234221
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300,w-400,b-20_FF0000/test_path.jpg`);
235222
});
236223

237-
it('transformation with empty key and empty value', function () {
224+
it('transformation with empty key and empty value', function () {
238225
const url = imagekit.url({
239226
path: "/test_path.jpg",
240227
transformation: [{
@@ -263,11 +250,11 @@ describe("URL generation", function () {
263250
const url = imagekit.url({
264251
path: "/test_path.jpg",
265252
transformation: [{
266-
overlayImage: ""
253+
effectShadow: ""
267254
}]
268255
})
269256

270-
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:oi-/test_path.jpg`);
257+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:e-shadow-/test_path.jpg`);
271258
});
272259

273260
it('transformation with - value', function () {
@@ -299,32 +286,6 @@ describe("URL generation", function () {
299286
rotation: 90,
300287
blur: 10,
301288
named: "some_name",
302-
overlayX: 35,
303-
overlayY: 35,
304-
overlayFocus: "bottom",
305-
overlayHeight: 20,
306-
overlayWidth: 20,
307-
overlayImage: "/folder/file.jpg", // leading slash case
308-
overlayImageTrim: false,
309-
overlayImageAspectRatio: "4:3",
310-
overlayImageBackground: "0F0F0F",
311-
overlayImageBorder: "10_0F0F0F",
312-
overlayImageDPR: 2,
313-
overlayImageQuality: 50,
314-
overlayImageCropping: "force",
315-
overlayText: "two words",
316-
overlayTextFontSize: 20,
317-
overlayTextFontFamily: "Open Sans",
318-
overlayTextColor: "00FFFF",
319-
overlayTextTransparency: 5,
320-
overlayTextTypography: "b",
321-
overlayBackground: "00AAFF55",
322-
overlayTextEncoded: "b3ZlcmxheSBtYWRlIGVhc3k%3D",
323-
overlayTextWidth: 50,
324-
overlayTextBackground: "00AAFF55",
325-
overlayTextPadding: 40,
326-
overlayTextInnerAlignment: "left",
327-
overlayRadius: 10,
328289
progressive: true,
329290
lossless: true,
330291
trim: 5,
@@ -336,12 +297,14 @@ describe("URL generation", function () {
336297
effectUSM: "2-2-0.8-0.024",
337298
effectContrast: true,
338299
effectGray: true,
300+
effectShadow: 'e-shadow-bl-15_st-40_x-10_y-N5',
301+
effectGradient: 'from-red_to-white',
339302
original: true,
340303
raw: "h-200,w-300,l-image,i-logo.png,l-end"
341304
}]
342305
})
343306

344-
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300,w-400,ar-4-3,q-40,c-force,cm-extract,fo-left,f-jpeg,r-50,bg-A94D34,b-5-A94D34,rt-90,bl-10,n-some_name,ox-35,oy-35,ofo-bottom,oh-20,ow-20,oi-folder@@file.jpg,oit-false,oiar-4:3,oibg-0F0F0F,oib-10_0F0F0F,oidpr-2,oiq-50,oic-force,ot-two%20words,ots-20,otf-Open%20Sans,otc-00FFFF,oa-5,ott-b,obg-00AAFF55,ote-b3ZlcmxheSBtYWRlIGVhc3k%3D,otw-50,otbg-00AAFF55,otp-40,otia-left,or-10,pr-true,lo-true,t-5,md-true,cp-true,di-folder@@file.jpg,dpr-3,e-sharpen-10,e-usm-2-2-0.8-0.024,e-contrast-true,e-grayscale-true,orig-true,h-200,w-300,l-image,i-logo.png,l-end/test_path.jpg`);
307+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:h-300,w-400,ar-4-3,q-40,c-force,cm-extract,fo-left,f-jpeg,r-50,bg-A94D34,b-5-A94D34,rt-90,bl-10,n-some_name,pr-true,lo-true,t-5,md-true,cp-true,di-folder@@file.jpg,dpr-3,e-sharpen-10,e-usm-2-2-0.8-0.024,e-contrast-true,e-grayscale-true,e-shadow-e-shadow-bl-15_st-40_x-10_y-N5,e-gradient-from-red_to-white,orig-true,h-200,w-300,l-image,i-logo.png,l-end/test_path.jpg`);
345308
});
346309
});
347310

0 commit comments

Comments
 (0)