A drawing guide that lines up on a desktop can drift on a phone if the overlay coordinates were saved in screen pixels. The browser may scale the image, letterbox it or crop it. Keep the coordinates in the source image’s coordinate space and apply the same display transform to both layers.
Save positions relative to the image
For a source image of width W and height H, store each point as u = x / W and v = y / H. A point halfway across the picture stays at u = 0.5 regardless of the layout. Store the endpoints of a construction line in the same format. If you let people drag a guide, run the inverse transform before saving the new position.
Account for the space the image actually occupies
Suppose a 1200 × 800 image sits inside a 400 × 400 frame centered with object-fit: contain. The image displays at about 400 × 267, with about 67 pixels above it. The guide at (0.5, 0.25) lands near (200, 133) within the frame. Scaling directly against the frame would place it at (200, 100), visibly above the intended feature.
One way to compute the position, assuming centered content, is:
const scale = Math.min(frameWidth / imageWidth, frameHeight / imageHeight); const width = imageWidth * scale; const height = imageHeight * scale; const x = (frameWidth - width) / 2 + u * width; const y = (frameHeight - height) / 2 + v * height; If your layout uses a different object-position, adapt the offsets. With cover, use the larger scale and clip the overlay to the same frame. An SVG placed in the same layout as the image can also handle the transform through its viewBox and aspect-ratio settings.
Try a deliberately awkward test
Build a test image with marked corners and a centered cross. Save one guide at each corner and a second guide through the cross. Resize from portrait to landscape, then repeat with a very wide image. Test the opposite operation as well: drag a guide to the cross, resize, and verify it stays there. A failure at the corners usually reveals a scaling error; an offset across the whole image usually points to the origin.
One example of a workflow that uses photo construction guides is Loomis Drawing, a portrait practice tool from our team.