input
Ameer & Samar, typed as given
Arabic chat alphabet, where digits stand in for letters with no Latin equivalent: 3 is ع, 7 is ح. Before anything can be set, this has to be resolved into real script.
latin input
Arabic calligraphy composed as real typography, then used to constrain what a generative image model is allowed to draw.
khatt — Arabic for line, script, or calligraphy.
Working on projects around weddings and celebrations, I kept seeing the same request: a couple's names set in Arabic calligraphy, to be used as a monogram on an invitation or a backdrop. In Latin script a generative model will do that readily. In Arabic it will not — it returns strokes with the texture of script and none of the letters.
That gap is what this is about. I built it to learn where it comes from and whether it can be closed by constraining the model rather than by asking it more nicely.




Historical plates, public domain. Sources listed at the foot of the page.
Arabic script is cursive and contextual. A letter changes shape depending on whether it stands alone or sits at the start, middle or end of a word, and letters join to their neighbours. A calligrapher works within those rules and arranges the result into a shape — the Diwani plate above is one sentence massed into a crescent.
That is the part generative models get wrong. Asked for Arabic calligraphy, they produce the texture of script without the script: strokes that look correct at a glance and resolve into nothing.
Two names, from typed input to an ornamented piece. Everything up to the last step is deterministic: the names are mapped into Arabic script, set in a chosen face, composed, and fitted to a silhouette picked in advance. Only then does a model run, and what it receives is the contour of the actual words rather than a prompt describing them. Its job is ornament, not spelling.
Ameer & Samar, typed as given
Arabic chat alphabet, where digits stand in for letters with no Latin equivalent: 3 is ع, 7 is ح. Before anything can be set, this has to be resolved into real script.
latin input
أمير و سمر
Mapped to Arabic and joined with و, not an ampersand. A Latin mark inside a right-to-left run reorders unpredictably under the bidi algorithm.
rtl, bidi-safe
Set in Aref Ruqaa
The tool ships five Arabic faces. Four are book faces built for reading. Aref Ruqaa has calligraphic weight distribution and a long descending ع — the one that survives being ornamented.
5 faces compared
Stacked and optically centred
Centred on real ink bounds via getBBox(), not on the text baseline. Arabic baselines sit off centre because of ascenders and descenders, so baseline-centring looks wrong.
svg, vector
A tulip silhouette, chosen first
The outline is picked before generation, not drawn around the result. The composition has to resolve into this shape, which makes it a constraint on layout rather than a frame added afterwards.
constraint, not frame
1,268 Thuluth image/caption pairs
Each image cleaned and normalised, captioned to a fixed trigger phrase, and deduplicated by MD5 hash so no plate is learned twice. A second Kufi set alongside it. A LoRA trained on this and pinned to a version hash, so any output can be traced back to the exact weights that produced it.
1,268 pairs
Inverted to white on black
This is what the model actually receives: the contour of the real words inside the chosen silhouette. Not a prompt describing Arabic — the shape of it.
controlnet input
Two terms pulling against each other
Filling the silhouette is rewarded; any stroke falling outside it is subtracted. Both failures are real: too small and the shape stays empty, too large and the strokes break out of it. The lowest overflow of any candidate belongs to the one that fills almost nothing, so neither term can be optimised on its own.
fill rewarded · overflow penalised
What is left for the ornament
Subtracting the letterforms from the silhouette leaves the region the generative step is allowed to work in — 78% of the shape here. The letterforms and everything beyond the outline are held, so the model is given a space to fill rather than a picture to reinterpret.
letterforms held
Ornament worked around the letterforms
The only generative step. Guidance is kept low at 3 with 28 inference steps; pushed higher, the model asserts its own idea of the letterforms and the conditioning stops holding.
guidance 3 · 28 steps
Stages 1–5 and 7–9 are deterministic and reproducible. Stage 6 is a sample of the training set rather than a step applied to these names. Stage 10 is the generative step, shown below at four ornament densities.




The same composition at four ornament densities. The letterforms and the silhouette are held fixed; only the fill changes.
A browser tool, written in plain JavaScript and SVG with no framework and no build step, plus a small Node server that proxies to Replicate so the API token stays out of the browser. The generation step runs against a LoRA trained on a curated Arabic calligraphy set, pinned to an explicit version so output stays comparable over time.
http. Single generation, generic transform, and a chained multi-step pipeline.Guidance is kept low deliberately. Pushed higher, the model asserts its own idea of the letterforms and the structural conditioning stops holding.
A research tool, built to test one question: whether a generative model can be constrained to respect a script it renders badly on its own.
The transferable part is the approach: treat the model as a renderer working inside a structure you control, rather than as something you ask for text and hope. That generalises to any script a model handles badly.