<aside>
This document details the core image processing pipeline of the backend system, which transforms an uploaded image into corresponding code. The process involves several key stages, each employing specific technologies and strategies to analyse the image and extract meaningful information for code generation.
</aside>
<aside>
uploads/<request_id>/images/
).<aside>
For images that represent long web pages or complex layouts, an initial segmentation step may be performed to break them down into more manageable sections.
uploads/<request_id>/images/
). These segments will then be processed individually in subsequent stages. If no segmentation is performed, the original image proceeds to the next stage.
</aside><aside>
This stage focuses on identifying individual UI elements within the image (or its segments) and determining their precise locations.
uploads/<request_id>/labels/<image_name>.json
).
</aside><aside>
This phase examines each detected component more closely to understand its content, purpose, and visual attributes.
Heuristic Approach:
Hierarchy Generation: The labels we get here are converted into hierarchy, considering the parent-child relationships of components.
Image Asset Handling: The media elements are categorised according to their label names and added to this hierarchy as assets for each particular component. Later, these assets are cropped from the original image and saved (e.g., in uploads/<request_id>/final/assets/
).
Styling and Layout: The styling and layout calculation in this code is a sophisticated process that transforms spatial data from UI elements into usable CSS and positioning information.
1. Coordinate System Conversion
The system works with two coordinate systems:
2. Relational Positioning
The code calculates positioning for both:
For each component, it calculates these positions as percentages.
3. Positioning Strategy Selection
Determines whether components should use absolute or relative positioning based on:
4. Special Handling for Media Elements
Media elements (images, icons) are treated differently:
5. Tailwind CSS Class Generation
For each component, the system generates appropriate Tailwind CSS classes:
relative
, absolute
w-[30%]
, h-[50%]
top-[10%]
, left-[5%]
It generates CSS classes by determining the arbitary values through percentage calculations.
6. Responsive Design Considerations
The percentage-based calculations ensure the layout can be responsive.
Color Analysis: It creates a "medialess" version of the image by removing all media elements For each component, it:
Non-Heuristic (AI-Driven) Approach:
<aside>
</aside>
<aside>
</aside>
This pipeline represents a sophisticated approach to converting visual designs into code, blending traditional image processing techniques with advanced AI-driven analysis to achieve a functional and representative output.