On a 1600 × 900 photo, place the start at (224, 702), the bend at (800, 495), and the target at (1088, 207). The camera heads from the lower left toward the bend, then rises toward the target. The arrow at the end points up and right at 45°. Calculate that same angle directly from normalized coordinates and the arrow tilts to about 61°.
Those three marks are enough to render a trajectory plate, a copy of the photo with a red curve and arrow overlaid. Store the anchors relative to the photo, then fit and render the curve in the pixel space of the export. The JavaScript below implements that pipeline with a reproducible fixture.
For a photo displayed with object-fit: contain, compute the displayed image rectangle inside the editor. Pointer events report viewport coordinates, so use the rectangle in viewport coordinates too. This example assumes an untransformed, borderless editor with a centered photo.
function normalizePointer(event, editorRect, imageWidth, imageHeight) {
const scale = Math.min(
editorRect.width / imageWidth,
editorRect.height / imageHeight,
);
if (!(scale > 0) || !Number.isFinite(scale)) return null;
const width = imageWidth * scale;
const height = imageHeight * scale;
const left = editorRect.left + (editorRect.width - width) / 2;
const top = editorRect.top + (editorRect.height - height) / 2;
const u = (event.clientX - left) / width;
const v = (event.clientY - top) / height;
return u >= 0 && u <= 1 && v >= 0 && v <= 1 ? [u, v] : null;
}
Clicks in the letterbox return null. A position of [0.5, 0.55] stays halfway across and 55% down when the editor resizes. If the editor supports cropping, choose the crop before drawing or remap the stored anchors through the crop transform. Render the same crop in both the source photo and the guide. Device pixel ratio affects a preview canvas backing buffer. The exported PNG receives its own explicit width and height. CSS Images specification for object-fit · CSSOM View pointer coordinates
Convert each stored [u, v] to [u × width, v × height] before measuring distances. A centripetal Catmull–Rom segment runs from p1 to p2 and uses its neighbors p0 and p3 to determine the shape. Each knot interval is the square root of the Euclidean distance between adjacent points. Centripetal spacing avoids cusps and self-intersections within an individual nondegenerate cubic segment. The full path can still cross itself when there are enough segments. Yuksel, Schaefer, and Keyser, On the Parameterization of Catmull–Rom Curves
At the ends, reflect the adjacent anchor through the endpoint to make a virtual neighbor. Reject consecutive anchors closer than one export pixel to keep the knot spans well defined. The one-pixel cutoff and 48 samples per segment are choices for this example. For longer paths, choose sample density by screen-space error.
const distance = ([ax, ay], [bx, by]) => Math.hypot(bx - ax, by - ay);
const reflect = ([x, y], [nx, ny]) => [2 * x - nx, 2 * y - ny];
function interpolate(a, b, ta, tb, t) {
const fraction = (t - ta) / (tb - ta);
return [
a[0] + (b[0] - a[0]) * fraction,
a[1] + (b[1] - a[1]) * fraction,
];
}
function sampleSegment(p0, p1, p2, p3, steps) {
const t0 = 0;
const t1 = t0 + Math.sqrt(distance(p0, p1));
const t2 = t1 + Math.sqrt(distance(p1, p2));
const t3 = t2 + Math.sqrt(distance(p2, p3));
return Array.from({ length: steps }, (_, index) => {
const t = t1 + (t2 - t1) * (index + 1) / steps;
const a1 = interpolate(p0, p1, t0, t1, t);
const a2 = interpolate(p1, p2, t1, t2, t);
const a3 = interpolate(p2, p3, t2, t3, t);
const b1 = interpolate(a1, a2, t0, t2, t);
const b2 = interpolate(a2, a3, t1, t3, t);
return interpolate(b1, b2, t1, t2, t);
});
}
function buildPath(anchors, width, height) {
if (![width, height].every(size => Number.isInteger(size) && size > 0)) {
throw new Error("Provide positive integer export dimensions");
}
if (anchors.length < 3 || anchors.some(point =>
point.length !== 2 || point.some(value => !Number.isFinite(value) || value < 0 || value > 1)
)) {
throw new Error("Provide start, bend, and target in normalized image coordinates");
}
const pixels = anchors.map(([u, v]) => [u * width, v * height]);
if (pixels.some((point, index) => index > 0 && distance(pixels[index - 1], point) < 1)) {
throw new Error("Separate adjacent anchors");
}
const start = pixels[0];
const beforeTarget = pixels.at(-2);
const target = pixels.at(-1);
const path = [start];
for (let i = 0; i < pixels.length - 1; i++) {
const p1 = pixels[i];
const p2 = pixels[i + 1];
const p0 = pixels[i - 1] ?? reflect(p1, p2);
const p3 = pixels[i + 2] ?? reflect(p2, p1);
path.push(...sampleSegment(p0, p1, p2, p3, 48));
}
const angle = Math.atan2(target[1] - beforeTarget[1], target[0] - beforeTarget[0]);
return { path, target, angle };
}
The segment samples skip p1 and include p2, so the concatenated polyline contains each shared endpoint once. The spline parameter drives interpolation. To animate a cursor at uniform apparent speed in an editor preview, build a cumulative chord-length table from the sampled vertices and interpolate at equal distances along it.
Reflection makes the final chord and its virtual continuation collinear with equal knot spacing. The terminal tangent therefore points along target − beforeTarget. For a different endpoint rule, take the derivative at the endpoint or estimate it from a short secant just behind the tip on the rendered curve. Math.atan2(dy, dx) preserves the quadrant. Canvas y increases downward, so a negative angle points above the positive x-axis. ECMAScript Math.atan2 · HTML Canvas 2D coordinate space
For a tip (x, y), wing length L, and half-wing angle φ, place the rear of each wing at (x − L cos(θ ± φ), y − L sin(θ ± φ)). Connect the rear points to the tip and render both over the photo. Scale stroke and wing lengths with the short edge to keep their relative size consistent across exports. Leave a little room around the target for the arrow's footprint.
function renderPlate(photo, anchors, width, height) {
// photo is decoded and cropped to the export aspect ratio.
const { path, target: [x, y], angle } = buildPath(anchors, width, height);
const canvas = document.createElement("canvas");
canvas.width = width;
canvas.height = height;
const ctx = canvas.getContext("2d");
ctx.drawImage(photo, 0, 0, width, height);
const scale = Math.min(width, height);
ctx.strokeStyle = "#e32323";
ctx.lineWidth = scale * 0.008;
ctx.lineCap = "round";
ctx.lineJoin = "round";
ctx.beginPath();
ctx.moveTo(...path[0]);
for (const point of path.slice(1)) ctx.lineTo(...point);
ctx.stroke();
const length = scale * 0.038;
const spread = Math.PI / 6;
const wing = direction => [x - length * Math.cos(direction), y - length * Math.sin(direction)];
ctx.beginPath();
ctx.moveTo(...wing(angle - spread));
ctx.lineTo(x, y);
ctx.lineTo(...wing(angle + spread));
ctx.stroke();
return canvas;
}
The fixture below checks the start, the join, the tip, and the arrow angle. Pass the same inputs and a decoded 16:9 photo to renderPlate, then use canvas.toBlob(callback, "image/png") for the plate. Keep the clean photo as a separate input. HTML Canvas export API
const anchors = [[0.14, 0.78], [0.50, 0.55], [0.68, 0.23]];
const { path, target, angle } = buildPath(anchors, 1600, 900);
const near = (point, expected) => distance(point, expected) < 1e-6;
console.assert(path.length === 97);
console.assert(near(path[0], [224, 702]));
console.assert(near(path[48], [800, 495]));
console.assert(near(path.at(-1), target) && near(target, [1088, 207]));
console.assert(Math.abs(angle + Math.PI / 4) < 1e-6);
For a drawn move, pair the unmarked photo with its trajectory plate. For a motion clone, use one or two product photos as appearance references and a curated video for camera timing and movement. A short, single-take orbit or push-in gives the model a more legible move to follow. Trim the reference to that take and use footage and photos you have permission to reuse. The Seedance team documents how multimodal inputs can reference separate aspects of a shot, including camera movement. Seedance 2.0 launch and reference examples · Seedance 2.5 reference workflows
| Workflow | Appearance input | Motion input | Review the result for |
|---|---|---|---|
| Draw a path | Clean source photo in the chosen crop | The same crop with the red path and arrow | One continuous move, the intended turn and finish, stable scene geometry, and frames free of guide marks |
| Clone a move | One or two images of the same product | A curated video with the desired orbit, push-in, or reveal | The expected direction and timing, stable packaging and logos, and a scene free of stray elements from the reference |
For example, a drawn-path instruction can read “Use the clean image for the storefront and the marked image for camera direction. Start low and left, ease around the sign, and settle on the door in a single shot. Render the finished shot with the guide removed.” The plate encodes image-plane intent. Depth, occlusion, speed, and how closely the move follows the plate depend on the generated result.
To test a new preset, hold the source photo, crop, duration, and model settings fixed. Render the proof once with the clean photo and instructions alone and once with the plate added. Review the start, turn, and finish for path adherence, then scrub the clip for red pixels and scene drift. For motion cloning, swap only the motion reference and check whether the move changes while the subject stays recognizable.
The workflow behind this example is available in the studio I’m launching. Draw the three marks on one photo or use a curated clip to transfer a move onto your own product. MotionPack
This article was drafted with AI.