Skip to content

Commit e59b5a7

Browse files
committed
feat(transformation): add colorReplace and distort transformations; update tests for new parameters
1 parent 370cf0f commit e59b5a7

4 files changed

Lines changed: 112 additions & 1 deletion

File tree

src/lib/transformation-utils.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ export const supportedTransforms: { [key: string]: string } = {
6060
sharpen: 'e-sharpen',
6161
unsharpMask: 'e-usm',
6262
gradient: 'e-gradient',
63+
colorReplace: 'cr',
64+
distort: 'e-distort',
6365

6466
// Other flags & finishing
6567
progressive: 'pr',

src/resources/helper.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,11 @@ function processOverlay(overlay: Transformation['overlay']): string | undefined
309309
break;
310310
}
311311

312+
// Add layerMode if present (only applicable to certain overlay types)
313+
if (overlay?.layerMode) {
314+
entries.push(`lm-${overlay.layerMode}`);
315+
}
316+
312317
const { x, y, focus } = position;
313318
if (x) {
314319
entries.push(`lx-${x}`);

tests/custom-tests/url-generation/basic.test.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,6 +1342,9 @@ describe('URL generation', function () {
13421342
sharpen: 10,
13431343
unsharpMask: '2-2-0.8-0.024',
13441344
gradient: 'from-red_to-white',
1345+
// New transformation parameters
1346+
colorReplace: 'FF0000_50_00FF00',
1347+
distort: 'p-50_50_150_50_150_150_50_150',
13451348
original: true,
13461349
page: '2_4',
13471350
raw: 'h-200,w-300,l-image,i-logo.png,l-end',
@@ -1350,7 +1353,24 @@ describe('URL generation', function () {
13501353
});
13511354

13521355
expect(url).toBe(
1353-
`https://ik.imagekit.io/test_url_endpoint/test_path.jpg?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,x-10,y-20,xc-30,yc-40,fl-h,o-0.8,z-2,vc-h264,ac-aac,so-5,eo-15,du-10,sr-1440_1080,e-grayscale,e-upscale,e-retouch,e-genvar,e-dropshadow,e-changebg-prompt-car,e-edit-prompt-make it vintage,e-bgremove,e-contrast,e-shadow-bl-15_st-40_x-10_y-N5,e-sharpen-10,e-usm-2-2-0.8-0.024,e-gradient-from-red_to-white,orig-true,pg-2_4,h-200,w-300,l-image,i-logo.png,l-end`,
1356+
`https://ik.imagekit.io/test_url_endpoint/test_path.jpg?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,x-10,y-20,xc-30,yc-40,fl-h,o-0.8,z-2,vc-h264,ac-aac,so-5,eo-15,du-10,sr-1440_1080,e-grayscale,e-upscale,e-retouch,e-genvar,e-dropshadow,e-changebg-prompt-car,e-edit-prompt-make it vintage,e-bgremove,e-contrast,e-shadow-bl-15_st-40_x-10_y-N5,e-sharpen-10,e-usm-2-2-0.8-0.024,e-gradient-from-red_to-white,cr-FF0000_50_00FF00,e-distort-p-50_50_150_50_150_150_50_150,orig-true,pg-2_4,h-200,w-300,l-image,i-logo.png,l-end`,
13541357
);
13551358
});
1359+
1360+
it('should generate the correct URL when radius is provided as a string value', function () {
1361+
const url = client.helper.buildSrc({
1362+
urlEndpoint: 'https://ik.imagekit.io/test_url_endpoint',
1363+
transformationPosition: 'query',
1364+
src: '/test_path.jpg',
1365+
transformation: [
1366+
{
1367+
width: 400,
1368+
height: 300,
1369+
radius: '10_max_20_30',
1370+
},
1371+
],
1372+
});
1373+
1374+
expect(url).toBe(`https://ik.imagekit.io/test_url_endpoint/test_path.jpg?tr=w-400,h-300,r-10_max_20_30`);
1375+
});
13561376
});

tests/custom-tests/url-generation/overlay.test.ts

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,90 @@ describe('Overlay Transformation Test Cases', function () {
350350
`https://ik.imagekit.io/test_url_endpoint/tr:l-text,i-Every%20thing,lx-10,ly-20,lfo-center,lso-5,leo-15,ldu-10,w-bw_mul_0.5,fs-20,ff-Arial,co-0000ff,ia-left,pa-5,al-7,tg-b,bg-red,r-10,rt-N45,fl-h,lh-20,l-end:l-image,i-logo.png,lx-10,ly-20,lfo-center,lso-5,leo-15,ldu-10,w-bw_mul_0.5,h-bh_mul_0.5,rt-N45,fl-h,l-text,i-Nested%20text%20overlay,l-end,l-end:l-video,i-play-pause-loop.mp4,lx-10,ly-20,lfo-center,lso-5,leo-15,ldu-10,w-bw_mul_0.5,h-bh_mul_0.5,rt-N45,fl-h,l-end:l-subtitle,i-subtitle.srt,lx-10,ly-20,lfo-center,lso-5,leo-15,ldu-10,bg-red,co-0000ff,ff-Arial,fol-2_A1CCDD50,fsh-A1CCDD_3,l-end:l-image,i-ik_canvas,bg-FF0000,lx-10,ly-20,lfo-center,lso-5,leo-15,ldu-10,w-bw_mul_0.5,h-bh_mul_0.5,al-0.5,bg-red,e-gradient,r-max,l-end/base-image.jpg`,
351351
);
352352
});
353+
354+
it('should generate URL with image overlay using layer mode multiply', function () {
355+
const url = client.helper.buildSrc({
356+
transformationPosition: 'path',
357+
urlEndpoint: 'https://ik.imagekit.io/test_url_endpoint',
358+
src: '/base-image.jpg',
359+
transformation: [
360+
{
361+
overlay: {
362+
type: 'image',
363+
input: 'overlay.png',
364+
layerMode: 'multiply',
365+
},
366+
},
367+
],
368+
});
369+
expect(url).toBe(
370+
`https://ik.imagekit.io/test_url_endpoint/tr:l-image,i-overlay.png,lm-multiply,l-end/base-image.jpg`,
371+
);
372+
});
373+
374+
it('should generate URL with image overlay using layer mode cutter', function () {
375+
const url = client.helper.buildSrc({
376+
transformationPosition: 'path',
377+
urlEndpoint: 'https://ik.imagekit.io/test_url_endpoint',
378+
src: '/base-image.jpg',
379+
transformation: [
380+
{
381+
overlay: {
382+
type: 'image',
383+
input: 'mask.png',
384+
layerMode: 'cutter',
385+
},
386+
},
387+
],
388+
});
389+
expect(url).toBe(
390+
`https://ik.imagekit.io/test_url_endpoint/tr:l-image,i-mask.png,lm-cutter,l-end/base-image.jpg`,
391+
);
392+
});
393+
394+
it('should generate URL with image overlay using layer mode cutout', function () {
395+
const url = client.helper.buildSrc({
396+
transformationPosition: 'path',
397+
urlEndpoint: 'https://ik.imagekit.io/test_url_endpoint',
398+
src: '/base-image.jpg',
399+
transformation: [
400+
{
401+
overlay: {
402+
type: 'image',
403+
input: 'mask.png',
404+
layerMode: 'cutout',
405+
},
406+
},
407+
],
408+
});
409+
expect(url).toBe(
410+
`https://ik.imagekit.io/test_url_endpoint/tr:l-image,i-mask.png,lm-cutout,l-end/base-image.jpg`,
411+
);
412+
});
413+
414+
it('should generate URL with image overlay using layer mode displace', function () {
415+
const url = client.helper.buildSrc({
416+
transformationPosition: 'path',
417+
urlEndpoint: 'https://ik.imagekit.io/test_url_endpoint',
418+
src: '/base-image.jpg',
419+
transformation: [
420+
{
421+
overlay: {
422+
type: 'image',
423+
input: 'displacement-map.png',
424+
layerMode: 'displace',
425+
position: {
426+
x: '50',
427+
y: '50',
428+
},
429+
},
430+
},
431+
],
432+
});
433+
expect(url).toBe(
434+
`https://ik.imagekit.io/test_url_endpoint/tr:l-image,i-displacement-map.png,lm-displace,lx-50,ly-50,l-end/base-image.jpg`,
435+
);
436+
});
353437
});
354438

355439
describe('Overlay encoding test cases', function () {

0 commit comments

Comments
 (0)