AI-Assisted Design-to-Code: The Hard Part Is Image Slicing, Not Writing Code
This article examines why AI coding tools often reconstruct the structure of a visual-heavy design mockup but miss its texture and atmosphere. Based on a React + Next.js + Tailwind CSS experiment, it explains the image-slicing and layering decisions AI tends to overlook, then presents a practical workflow: manually decompose the design before prompting, feed structural decisions to the model, use CSS layer variables, and validate with overlay comparisons.
AI-Assisted Design-to-Code: The Hard Part Is Image Slicing, Not Writing Code
1. An Experiment That Looks Simple but Is Actually Painful
Recently I did something that sounds technically trivial: take a visually rich product mockup and reproduce it as close to 1:1 as possible as a React page that runs in the browser.
The stack was ordinary: React + Next.js + Tailwind CSS. For tools, I tried the main categories of intelligent coding tools available—conversational code assistants, command-line agents, AI-native editors, and online platforms specifically built for “screenshot to code” generation.
Before starting, my expectations were optimistic. After all, over the past two years, AI’s ability to look at an image and write code has been demonstrated repeatedly: upload a screenshot, and the model can identify layout structure, split components, generate semantic JSX and Tailwind class names, and even add hover states and responsive logic. For standardized interfaces such as admin dashboards and form pages, this path is indeed fairly mature.
The problem was that what I had was not an admin page but a visually heavy product landing page: dark fantasy style, a large scene background image, multiple layers of lighting, cards with glowing borders, character art and architectural scenes interwoven, and modules that transition naturally through gradient masks.
The final output can be summarized in one sentence: the structure was all correct, but the texture was completely gone.
The page did run. The hero section, entry cards, test module, character showcase area, statistics, and bottom story module—all the expected skeleton pieces were there. But once placed side by side with the original image, the gap was immediately obvious:
- The modules became “scattered” and lost the immersive overall feel of the original;
- The background was treated by the model as a solid color or simple gradient, flattening the layers entirely;
- Some areas showed repeated texture overlays, while other areas were too dark to read;
- Card proportions were distorted, and the visual hierarchy of text—title, subtitle, decorative text—was flattened;
- Most importantly, complex image regions were not correctly “cut apart,” so the page had DOM structure but no product texture.
2. What AI Actually “Cannot See”
Reviewing the whole process, I found a systematic blind spot in current AI coding tools for design mockup reconstruction. The model is good at semantic recognition, but reconstruction actually requires visual engineering decisions.
Specifically, the model can recognize:
- Here is a card, there is a button;
- The page overall is dark and fantasy-themed;
- The title font size is large and the body font size is small.
But what the model cannot judge on its own is:
First, which content should be sliced into images, and which should be reconstructed with real DOM.
This is the core decision point of the entire task. For a character card with a glowing border, should the border glow be simulated purely with CSS, or should a nine-slice background image be cut? For the halo behind the character art, should it be cut as a separate layer and overlaid with absolute positioning, or merged with the background into one large image? Different slicing choices determine the subsequent DOM structure, style complexity, maintainability, and responsive adaptation strategy. By default, the model tends toward “everything is DOM,” so many visual assets that should have been images are forcibly approximated with gradients and shadows. The texture naturally collapses.
Second, the hierarchy and fusion relationships between modules.
In the original image, the bottom of one module “blends” into the background of the next through a gradient mask, and character art crosses card boundaries to create visual tension. These cross-module hierarchy designs are almost invisible to code-generation models whose thinking habit is “component isolation”—they are more inclined to treat each section as an independent container with clear boundaries, and the original’s “sense of flow” disappears.
Third, vignettes, glows, atmosphere layers, and other elements that “have no content.”
The design contains many visual layers that do not carry information: a vignette darkening the four corners, ambient light at the top, and diffuse shadows behind cards. These layers are directly ignored in semantic recognition, yet they are precisely the source of the “premium feel.”
3. It Is Not a Prompt Problem; It Is a Workflow Problem
Like most people’s first reaction, I initially thought the prompts were not detailed enough. So I kept adding more:
Please reproduce the design mockup 1:1. Do not improvise.Strictly preserve the colors, proportions, and spacing of the original image.Pay attention to background layers and lighting effects.
There was some effect, but with diminishing returns. Prompts can improve the accuracy of colors and spacing, but they cannot give the model knowledge of “how this image should be sliced” out of thin air. Because slicing is fundamentally an engineering decision that must be made in advance, not a detail that can be improvised during generation.
Once I understood this, I completely reversed the workflow, and the problem was solved.
4. A Practical AI-Assisted Reconstruction Workflow
1. Complete the visual breakdown manually before letting AI write code
Before opening any AI tool, first do a structured breakdown of the original image the way a traditional frontend developer would when receiving a design mockup, and produce a “slicing list”:
- Background layer: slice the full-page background as one large image (or split it by module), carried via
backgroundor an absolutely positionedimg; - Atmosphere layer: vignettes, glows, smoke, etc., sliced separately as transparent PNG or WebP, overlaid with
position: absolute+pointer-events: none; - Content layer: titles, body text, buttons, forms—these must be implemented with real DOM to ensure accessibility and maintainability;
- Decorative graphics: glowing borders, dividers, icons—use CSS when possible; if not, slice them as images. Do not force CSS where it does not fit.
2. Feed the breakdown to the model, not just the screenshot
With the list in hand, the role of the prompt changes from “making requests” to “communicating decisions”:
Page structure:1. Hero section: background is the full image bg-hero.webp, height 100vh,title and buttons are real DOM, bottom overlays a 200px gradient masktransitioning to the next module.2. Character card section: three cards, glowing borders use nine-slice border images,character art extends 40px above the card top, z-index higher than the card background....
At this point, the AI’s performance changes dramatically—because what it is best at is “writing code according to an explicit structure,” not “looking at an image and guessing the structure.”
3. Use CSS variables and layered containers to lock down the visual system
For multi-layer overlay scenarios, it is advisable to explicitly model the hierarchy in the implementation:
:root {--layer-bg: 0; /* Background layer */--layer-atmos: 10; /* Atmosphere layer */--layer-card: 20; /* Content card */--layer-figure: 30; /* Cross-boundary character art */--layer-mask: 40; /* Transition mask */}
Each layer corresponds to a semantic container convention. When AI modifies any layer in later iterations, it will not break the overall hierarchy—this is far more reliable than repeatedly reminding it to “pay attention to hierarchy” in prompts.
4. During acceptance, compare “feel,” not just structure
The final step is to establish visual acceptance criteria. The method I used was to overlay the original image and the implemented page at 50% opacity and check item by item—whether background blending is continuous, whether dark areas are readable, whether glow overflows, and whether card proportions match. Anything that is “structurally correct but feels wrong” can almost always be traced back to a wrong slicing decision.
5. Final Thoughts
This experiment gave me a clearer understanding of “AI looks at an image and writes code”: code-generation capability is no longer the bottleneck; the upfront decisions of visual engineering are. AI has compressed the cost of “writing React” to near zero, which instead makes the seemingly old craft of “slicing” valuable again—because who decides the boundary between images and DOM, and who defines the relationship between layers and masks, directly determines whether the final product is “a page that runs” or “a polished piece of work.”
For developers, this means the right way to collaborate with AI is not “give an image, wait for the result, tweak the prompt,” but “do the engineering breakdown first, then let AI execute.” Machines handle capacity; humans handle judgment—at least for visual reconstruction, this division of labor will not change in the short term.
