# Phase 2, Step 3: Automate Card Design Population & Export This document outlines the process for automating the creation of the final "On This Day" collectible card images by populating a design template with daily fetched data and (if applicable) generated images. ## Key Objectives: * Develop scripts to take the structured daily data (e.g., JSON from P2-S1) and any generated images (from P2-S2) as input. * Use the chosen design tool's scripting capabilities or a code-based image generation approach to populate the card template. * Automate the export of the final, populated card designs to a standard image format (e.g., PNG, JPG). * Ensure consistent output quality and manage any errors during the design generation process. ## Prerequisites: * **Completed P1-S2:** A digital card template designed with clear placeholders, and a design tool selected that supports automation (e.g., Scribus with Python, HTML/CSS with Puppeteer/Playwright, Google Slides with Apps Script). * **Completed P2-S1:** Scripts that automatically fetch daily data and save it in a structured format (e.g., `YYYY-MM-DD-data.json`). * **Completed P2-S2 (If Applicable):** Scripts that automatically generate and save daily images (e.g., `YYYY-MM-DD-ai-image.png`). ## Actionable Steps: 1. **Confirm Design Automation Approach:** * Revisit the chosen design tool from P1-S2 and its automation capabilities. * **Scribus:** Prepare Python scripts to interact with Scribus via its scripting API. * **HTML/CSS + Headless Browser (Puppeteer/Playwright):** * Develop/refine the HTML template to be easily populated with JavaScript. * Write a script (Node.js or Python) to inject data into the HTML, render it in the headless browser, and take a screenshot. * **ImageMagick/GraphicsMagick:** Develop shell scripts or use wrappers in a programming language to layer text and images onto a base template. * **Google Slides + Apps Script:** Write Google Apps Script functions to duplicate a template slide, populate placeholders from a data source (e.g., the JSON file, or a Google Sheet fed by P2-S1 script), and export as an image. 2. **Develop Data Ingestion Script:** * Write code to read and parse the daily structured data file (e.g., `YYYY-MM-DD-data.json` from P2-S1). * If applicable, identify the path to the daily generated image (e.g., `YYYY-MM-DD-ai-image.png` from P2-S2). 3. **Implement Template Population Logic:** * For each data point in the ingested data: * Map it to the corresponding placeholder in your card template. * Use the chosen tool's scripting API or DOM manipulation (for HTML/CSS) to insert the text. * Handle text formatting: font, size, color, alignment, line breaks, text fitting within defined boxes. This might require careful calculations or trial and error. * If dynamic images are used, load and place the image into its designated area in the template. 4. **Automate Image Export:*** Once the template is populated, script the export of the final card as an image file (PNG or JPG preferred for web/NFT use). * Define output resolution and quality settings. * Use a consistent naming convention for the final card images (e.g., `YYYY-MM-DD-Card-Final.png`). * Store these final images in a designated output directory. 5. **Error Handling & Quality Checks:** * **Missing Data/Images:** How does the script behave if parts of the input data or the AI image are missing? (e.g., use default values, leave sections blank, log an error and skip). * **Text Overflow:** Implement checks or strategies to handle text that might be too long for its designated area (e.g., truncate, reduce font size dynamically if possible, though this adds complexity). * **Image Placement Issues:** Ensure images are correctly scaled and positioned. * **Logging:** Log the process, including successful card generations and any errors encountered (e.g., template not found, data parsing errors, export failures). 6. **Integration with Previous Steps:** * Ensure this script can be triggered after the data fetching (P2-S1) and image generation (P2-S2, if used) scripts have successfully completed. * The output of P2-S1 (and P2-S2) is the direct input for this P2-S3 script. 7. **Testing:** * Test thoroughly with various sample data files from P2-S1 (and sample images from P2-S2). * Check for consistency in output quality, formatting, and adherence to the design. * Verify error handling works as expected. ## Deliverables for this Step: * A script (or set of scripts) that automates the population of the card template and exports final card images. * Clear documentation on how to run the script and its dependencies. * Sample final card images generated by the script. * Documented error handling for the design generation process. This step is the core of the visual output automation, bringing together the data and design into the final product.