Skip to content

Commit dcbcf76

Browse files
committed
feat(api): add support for x_center, y_center, and anchor_point in overlay positioning
1 parent 5a87ef0 commit dcbcf76

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

lib/imagekitio/helpers/helper.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -635,11 +635,17 @@ def add_overlay_properties(parts, overlay)
635635
if position
636636
x = safe_get(position, :x)
637637
y = safe_get(position, :y_)
638+
x_center = safe_get(position, :x_center)
639+
y_center = safe_get(position, :y_center)
638640
focus = safe_get(position, :focus)
641+
anchor_point = safe_get(position, :anchor_point)
639642

640643
parts << "lx-#{x}" if x
641644
parts << "ly-#{y}" if y
645+
parts << "lxc-#{x_center}" if x_center
646+
parts << "lyc-#{y_center}" if y_center
642647
parts << "lfo-#{focus}" if focus
648+
parts << "lap-#{anchor_point}" if anchor_point
643649
end
644650

645651
# Add timing properties

test/imagekitio/custom-tests/url-generation/overlay_test.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -856,4 +856,32 @@ def test_should_work_with_plain_hashes_for_text_overlay
856856
expected = "https://ik.imagekit.io/test_url_endpoint/tr:w-300,h-200,l-text,i-Hello%20World,lx-10,ly-20,lfo-center,fs-20,co-FF0000,l-end/base-image.jpg"
857857
assert_equal(expected, url)
858858
end
859+
860+
# Test for x_center, y_center, and anchor_point
861+
def test_should_generate_url_with_overlay_using_xcenter_ycenter_and_anchorpoint
862+
# Using hash format to avoid type conversion issues with arithmetic expressions
863+
url = @client.helper.build_url(
864+
{
865+
src: "/base-image.jpg",
866+
url_endpoint: "https://ik.imagekit.io/test_url_endpoint",
867+
transformation_position: :path,
868+
transformation: [
869+
{
870+
overlay: {
871+
type: :image,
872+
input: "logo.png",
873+
position: {
874+
x_center: "bw_mul_0.5",
875+
y_center: "bh_mul_0.5",
876+
anchor_point: :top_left
877+
}
878+
}
879+
}
880+
]
881+
}
882+
)
883+
884+
expected = "https://ik.imagekit.io/test_url_endpoint/tr:l-image,i-logo.png,lxc-bw_mul_0.5,lyc-bh_mul_0.5,lap-top_left,l-end/base-image.jpg"
885+
assert_equal(expected, url)
886+
end
859887
end

0 commit comments

Comments
 (0)