Skip to content

Commit 0fcec28

Browse files
committed
feat(api): add xCenter, yCenter, and anchorPoint parameters for overlay positioning
1 parent 6853a32 commit 0fcec28

2 files changed

Lines changed: 36 additions & 1 deletion

File tree

src/resources/helper.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,16 +314,25 @@ function processOverlay(overlay: Transformation['overlay']): string | undefined
314314
entries.push(`lm-${overlay.layerMode}`);
315315
}
316316

317-
const { x, y, focus } = position;
317+
const { x, y, xCenter, yCenter, focus, anchorPoint } = position;
318318
if (x) {
319319
entries.push(`lx-${x}`);
320320
}
321321
if (y) {
322322
entries.push(`ly-${y}`);
323323
}
324+
if (xCenter) {
325+
entries.push(`lxc-${xCenter}`);
326+
}
327+
if (yCenter) {
328+
entries.push(`lyc-${yCenter}`);
329+
}
324330
if (focus) {
325331
entries.push(`lfo-${focus}`);
326332
}
333+
if (anchorPoint) {
334+
entries.push(`lap-${anchorPoint}`);
335+
}
327336

328337
const { start, end, duration } = timing;
329338
if (start) {

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,30 @@ describe('Overlay Transformation Test Cases', function () {
434434
`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`,
435435
);
436436
});
437+
438+
it('should generate URL with xCenter, yCenter and anchorPoint top_left', function () {
439+
const url = client.helper.buildSrc({
440+
transformationPosition: 'path',
441+
urlEndpoint: 'https://ik.imagekit.io/test_url_endpoint',
442+
src: '/base-image.jpg',
443+
transformation: [
444+
{
445+
overlay: {
446+
type: 'image',
447+
input: 'logo.png',
448+
position: {
449+
xCenter: 100,
450+
yCenter: 200,
451+
anchorPoint: 'top_left',
452+
},
453+
},
454+
},
455+
],
456+
});
457+
expect(url).toBe(
458+
`https://ik.imagekit.io/test_url_endpoint/tr:l-image,i-logo.png,lxc-100,lyc-200,lap-top_left,l-end/base-image.jpg`,
459+
);
460+
});
437461
});
438462

439463
describe('Overlay encoding test cases', function () {
@@ -720,3 +744,5 @@ describe('Overlay encoding test cases', function () {
720744
expect(url).toBe(`https://ik.imagekit.io/demo/sample.jpg?tr=l-text,i-Minimal%20Text,l-end`);
721745
});
722746
});
747+
748+

0 commit comments

Comments
 (0)