Skip to content

Commit 2378655

Browse files
committed
feat: add support for new overlay position parameters xCenter, yCenter, and anchorPoint
1 parent c3800ae commit 2378655

6 files changed

Lines changed: 99 additions & 20 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Changelog
22

3+
## Version 5.3.0
4+
5+
1. **Enhancement:**
6+
- Added support for new overlay position parameters: `xCenter` (`lxc`), `yCenter` (`lyc`), and `anchorPoint` (`lap`) in overlay transformations
7+
38
## Version 5.2.2
49

510
1. Updated TypeScript types to allow string values for the `dpr` parameter in transformations, enabling support for arithmetic expressions and dynamic DPR values.

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@imagekit/javascript",
3-
"version": "5.2.2",
3+
"version": "5.3.0",
44
"description": "ImageKit Javascript SDK",
55
"main": "dist/imagekit.cjs.js",
66
"module": "dist/imagekit.esm.js",

src/interfaces/shared.ts

Lines changed: 61 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -136,12 +136,6 @@ export namespace ExtensionConfig {
136136
*/
137137
type: 'select_tags';
138138

139-
/**
140-
* Array of possible tag values. Combined length of all strings must not exceed 500
141-
* characters. Cannot contain the `%` character.
142-
*/
143-
vocabulary: Array<string>;
144-
145139
/**
146140
* Maximum number of tags to select from the vocabulary.
147141
*/
@@ -151,6 +145,14 @@ export namespace ExtensionConfig {
151145
* Minimum number of tags to select from the vocabulary.
152146
*/
153147
min_selections?: number;
148+
149+
/**
150+
* Array of possible tag values. The combined length of all strings must not exceed
151+
* 500 characters, and values cannot include the `%` character. When providing
152+
* large vocabularies (more than 30 items), the AI may not follow the list
153+
* strictly.
154+
*/
155+
vocabulary?: Array<string>;
154156
}
155157

156158
export interface SelectMetadata {
@@ -181,7 +183,10 @@ export namespace ExtensionConfig {
181183
min_selections?: number;
182184

183185
/**
184-
* Array of possible values matching the custom metadata field type.
186+
* An array of possible values matching the custom metadata field type. If not
187+
* provided for SingleSelect or MultiSelect field types, all values from the custom
188+
* metadata field definition will be used. When providing large vocabularies (above
189+
* 30 items), the AI may not strictly adhere to the list.
185190
*/
186191
vocabulary?: Array<string | number | boolean>;
187192
}
@@ -457,12 +462,6 @@ export namespace Extensions {
457462
*/
458463
type: 'select_tags';
459464

460-
/**
461-
* Array of possible tag values. Combined length of all strings must not exceed 500
462-
* characters. Cannot contain the `%` character.
463-
*/
464-
vocabulary: Array<string>;
465-
466465
/**
467466
* Maximum number of tags to select from the vocabulary.
468467
*/
@@ -472,6 +471,14 @@ export namespace Extensions {
472471
* Minimum number of tags to select from the vocabulary.
473472
*/
474473
min_selections?: number;
474+
475+
/**
476+
* Array of possible tag values. The combined length of all strings must not exceed
477+
* 500 characters, and values cannot include the `%` character. When providing
478+
* large vocabularies (more than 30 items), the AI may not follow the list
479+
* strictly.
480+
*/
481+
vocabulary?: Array<string>;
475482
}
476483

477484
export interface SelectMetadata {
@@ -502,7 +509,10 @@ export namespace Extensions {
502509
min_selections?: number;
503510

504511
/**
505-
* Array of possible values matching the custom metadata field type.
512+
* An array of possible values matching the custom metadata field type. If not
513+
* provided for SingleSelect or MultiSelect field types, all values from the custom
514+
* metadata field definition will be used. When providing large vocabularies (above
515+
* 30 items), the AI may not strictly adhere to the list.
506516
*/
507517
vocabulary?: Array<string | number | boolean>;
508518
}
@@ -782,8 +792,25 @@ export type Overlay = TextOverlay | ImageOverlay | VideoOverlay | SubtitleOverla
782792

783793
export interface OverlayPosition {
784794
/**
785-
* Specifies the position of the overlay relative to the parent image or video.
786-
* Maps to `lfo` in the URL.
795+
* Sets the anchor point on the base asset from which the overlay offset is
796+
* calculated. The default value is `top_left`. Maps to `lap` in the URL. Can only
797+
* be used with one or more of `x`, `y`, `xCenter`, or `yCenter`.
798+
*/
799+
anchorPoint?:
800+
| 'top'
801+
| 'left'
802+
| 'right'
803+
| 'bottom'
804+
| 'top_left'
805+
| 'top_right'
806+
| 'bottom_left'
807+
| 'bottom_right'
808+
| 'center';
809+
810+
/**
811+
* Specifies the position of the overlay relative to the parent image or video. If
812+
* one or more of `x`, `y`, `xCenter`, or `yCenter` parameters are specified, this
813+
* parameter is ignored. Maps to `lfo` in the URL.
787814
*/
788815
focus?:
789816
| 'center'
@@ -805,6 +832,15 @@ export interface OverlayPosition {
805832
*/
806833
x?: number | string;
807834

835+
/**
836+
* Specifies the x-coordinate on the base asset where the overlay's center will be
837+
* positioned. It also accepts arithmetic expressions such as `bw_mul_0.4` or
838+
* `bw_sub_cw`. Maps to `lxc` in the URL. Cannot be used together with `x`, but can
839+
* be used with `y`. Learn about
840+
* [Arithmetic expressions](https://imagekit.io/docs/arithmetic-expressions-in-transformations).
841+
*/
842+
xCenter?: number | string;
843+
808844
/**
809845
* Specifies the y-coordinate of the top-left corner of the base asset where the
810846
* overlay's top-left corner will be positioned. It also accepts arithmetic
@@ -813,6 +849,15 @@ export interface OverlayPosition {
813849
* [Arithmetic expressions](https://imagekit.io/docs/arithmetic-expressions-in-transformations).
814850
*/
815851
y?: number | string;
852+
853+
/**
854+
* Specifies the y-coordinate on the base asset where the overlay's center will be
855+
* positioned. It also accepts arithmetic expressions such as `bh_mul_0.4` or
856+
* `bh_sub_ch`. Maps to `lyc` in the URL. Cannot be used together with `y`, but can
857+
* be used with `x`. Learn about
858+
* [Arithmetic expressions](https://imagekit.io/docs/arithmetic-expressions-in-transformations).
859+
*/
860+
yCenter?: number | string;
816861
}
817862

818863
export interface OverlayTiming {

src/url.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,13 +196,22 @@ function processOverlay(overlay: Transformation["overlay"]): string | undefined
196196
entries.push(`lm-${layerMode}`);
197197
}
198198

199-
const { x, y, focus } = position;
199+
const { x, y, xCenter, yCenter, anchorPoint, focus } = position;
200200
if (x) {
201201
entries.push(`lx-${x}`);
202202
}
203203
if (y) {
204204
entries.push(`ly-${y}`);
205205
}
206+
if (xCenter) {
207+
entries.push(`lxc-${xCenter}`);
208+
}
209+
if (yCenter) {
210+
entries.push(`lyc-${yCenter}`);
211+
}
212+
if (anchorPoint) {
213+
entries.push(`lap-${anchorPoint}`);
214+
}
206215
if (focus) {
207216
entries.push(`lfo-${focus}`);
208217
}

test/url-generation/overlay.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,5 +579,25 @@ describe("Overlay encoding test cases", function () {
579579
});
580580
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:l-image,i-overlay-image.jpg,lm-displace,lx-10,ly-10,l-end/base-image.jpg`);
581581
});
582+
583+
it('should generate correct URL with xCenter, yCenter and anchorPoint', function () {
584+
const url = buildSrc({
585+
transformationPosition: "path",
586+
urlEndpoint: "https://ik.imagekit.io/test_url_endpoint",
587+
src: "/base-image.jpg",
588+
transformation: [{
589+
overlay: {
590+
type: "image",
591+
input: "overlay-image.jpg",
592+
position: {
593+
xCenter: 100,
594+
yCenter: 50,
595+
anchorPoint: "top_left"
596+
}
597+
}
598+
}]
599+
});
600+
expect(url).equal(`https://ik.imagekit.io/test_url_endpoint/tr:l-image,i-overlay-image.jpg,lxc-100,lyc-50,lap-top_left,l-end/base-image.jpg`);
601+
});
582602
});
583603
});

0 commit comments

Comments
 (0)