Converting WeChat Articles into Xiaohongshu Image Cards: Architecture and Implementation

    This article explains how to turn long-form WeChat Official Account posts into a sequence of portrait image cards for Xiaohongshu. It covers content extraction, a shared document model for multiple input formats, semantic pagination, template-based rendering, and optional AI-generated visuals. It also describes how to support generation history, single-card revisions, and ZIP downloads without rerunning the entire pipeline. only

    1. The Problem: One Article, Two Reading Formats

    Publishing the same content on multiple platforms often means changing its format. WeChat Official Accounts, a publishing channel within WeChat, commonly carry long-form articles with illustrations. Xiaohongshu, by contrast, emphasizes portrait image cards with limited space for text and a stronger focus on visual design.

    Manually adapting a long article means copying the text, splitting it into sections, applying a design template, exporting each card, and adjusting the layout until everything fits. For a long post, that can take hours. The goal is to automate that work: take an article as input and return a cover image followed by a sequence of content cards.

    The conversion pipeline looks like this:

    1. Source content (URL or local document)
    2. → Content retrieval and parsing
    3. → Structured intermediate representation
    4. → Content segmentation and layout planning
    5. → Image rendering
    6. → Image sequence export and post-processing

    The supported input formats determine how much preparation users need to do. The system should handle two main input paths.

    Article URLs. The user pastes a WeChat article link, and the server retrieves the page and extracts the main article. The challenge is separating the article from navigation, ads, and comments. DOM features such as the main content container’s CSS class and text density can help identify the body. The extraction pipeline also needs a policy for inline images: which ones to keep, how to compress them, and how to fit them into the card layout.

    Local document uploads. Common inputs include plain text, Markdown, Word, and PDF. Each format presents different parsing challenges:

    • Plain text (.txt): Easy to read, but it has no explicit document structure. Headings and paragraph boundaries may need to be inferred with heuristics.
    • Markdown (.md): Encodes heading levels and other structural elements directly, making it straightforward to parse into a document tree.
    • Word (.doc / .docx): A .docx file is a compressed XML package from which a parser can recover paragraphs, heading styles, and emphasis such as bold text.
    • PDF (.pdf): The most difficult format to parse, particularly when pages use multiple columns or mix text and images. These documents may require layout analysis, with OCR as a fallback when needed.

    Define a shared internal document model for heading levels, paragraphs, images, and emphasis. Each parser then has one job: convert its source format into that model. Segmentation and rendering can work from the same representation regardless of how the article entered the system.

    3. Core Conversion: Semantic Segmentation and Layout

    A Xiaohongshu card can typically hold around 150–300 Chinese characters. That range is a layout guideline, not a rule for where to split the article. Good pagination keeps ideas intact while leaving enough room for a readable design.

    Split by meaning before length

    A fixed character limit can cut an argument in half. Instead, build a section tree from the heading hierarchy, then group related paragraphs within each section so that each card presents a coherent unit. If a section is too long for one card, split it at paragraph boundaries.

    Use configurable templates

    Different cards serve different purposes, so the template system should distinguish among three common layouts:

    • Cover: A prominent title, a subtitle, and a visual element that gives readers a reason to open the post.
    • Content card: A body text area, a page number or sequence marker, and space for a brand watermark. The layout needs to balance information density with white space.
    • Closing card: A summary or call to action, such as an invitation to follow the account.

    Make AI-generated visuals optional

    Templates provide consistent layouts, but cards can look repetitive when they rely on the same visual assets. An image generation API can supply backgrounds and illustrations without replacing the template renderer.

    Make the integration configurable. Users can provide their own API endpoint and key, while the server calls the selected service through a common interface. This keeps the tool from depending on a single provider. In practice, generated backgrounds and illustrations improved the overall look of the cards.

    4. Rendering: From Structured Content to Images

    There are two main ways to turn the planned cards into images.

    Headless-browser rendering. Load an HTML template in a server-side headless browser, inject the structured content, and capture the result as an image. This approach lets the system reuse CSS and its layout capabilities. The trade-off is higher resource use, which makes browser instance pooling and concurrency control important.

    Direct drawing with a graphics library. Draw text and visual elements at explicit coordinates. This approach can offer better performance, but it shifts typography work into the application. Chinese line breaking, hanging punctuation, and font subsetting require additional handling.

    The rendering flow can be expressed as pseudocode:

    1. def render_card_set(doc, template_config):
    2. sections = semantic_split(doc) # Split the article into coherent sections
    3. cards = []
    4. cards.append(render_cover(doc.title, doc.summary, template_config))
    5. for i, sec in enumerate(sections):
    6. cards.append(render_content(sec, index=i, template_config=template_config))
    7. return pack_as_zip(cards) # Package the cards for download

    Typography and color also need explicit configuration. Subsetting Chinese fonts can reduce the size of the font assets used during rendering. For color, offer several preset palettes while allowing users to define their own.

    5. Product Workflow: History, Revisions, and Export

    The conversion pipeline generates the cards, but users also need a way to manage and revise the results.

    • Accounts: Support registration, sign-in, and password recovery, with token-based session management.
    • Generation history: Persist previous runs so users can revisit and reuse them. A typical setup stores the images in object storage and the associated metadata in a database.
    • Single-card rerendering: Let users revise an individual card without regenerating the entire sequence. This reduces rework and requires the rendering pipeline to support incremental execution at the card level.
    • ZIP download: Provide a one-click export for the complete image set. The server can build the archive asynchronously and return a download link. For larger jobs, a task queue keeps packaging work from causing request timeouts.

    6. Architecture Summary and Next Steps

    The system has five layers: ingestion accepts links and document uploads; parsing normalizes source formats; conversion handles semantic segmentation, layout planning, and optional image model calls; rendering produces the cards; and the application layer manages accounts, history, revisions, and downloads.

    The same architecture can evolve to support batch conversion, scheduled jobs, and multiple image aspect ratios from a single article. Performance data, such as which templates receive higher click-through rates, and direct user feedback can also inform future layout improvements. The value of the project goes beyond republishing articles: it brings structured content processing, image rendering, and optional model integration together in a single workflow.