Add a text watermark to every image in a folder. Idempotent — keeps .original/ backups so re-running re-applies on the clean source instead of stacking watermarks.
Watermarks every .jpg / .jpeg / .png / .webp in src. Backs up originals to <src>/.original/ on first run. Returns an array of { name, width, height, wm }.
watermarkOne({ inputPath, outputPath, options })
Watermarks a single image. Use this when you control your own backup strategy.
Options
{
text: string; // overlay text
position: "bottom-right" | "bottom-left" | "top-right" | "top-left" | "center";
textColor: string; // CSS color (hex / rgb / name)
strokeColor: string; // outline color for legibility on busy backgrounds
fontFamily: string; // any SVG-safe font stack
opacity: number; // 0-1
paddingPct: number; // edge padding as fraction of image width
heightPct: number; // watermark height as fraction of image width
backupDirName: string; // default ".original"
}
How it works
On first run, copies each image to <src>/.original/<name>.
Reads from .original/ so the watermark never stacks.
Sharp composites an SVG-rendered text layer onto the image.
Writes the result back to the original path.
Stroke-around-text rendering keeps the watermark legible on both light and dark backgrounds without needing a heavy background fill.