Systems Library / AI Capabilities / How to Build a Social Media Image Generator
AI Capabilities image generation

How to Build a Social Media Image Generator

Generate branded social media images on demand using AI templates.

Jay Banlasan

Jay Banlasan

The AI Systems Guy

An ai social media image generator for branded content produces a week's worth of visual content in an hour. I build these for businesses posting daily across platforms. Instead of designing each image from scratch, the system takes your content (a quote, a stat, a tip) and generates a branded visual using your colors, fonts, and style.

Consistency is the whole point. Every post looks like it belongs to the same brand.

What You Need Before Starting

Step 1: Define Platform Specifications

PLATFORM_SPECS = {
    "instagram_feed": {"width": 1080, "height": 1080, "aspect": "1:1"},
    "instagram_story": {"width": 1080, "height": 1920, "aspect": "9:16"},
    "linkedin": {"width": 1200, "height": 627, "aspect": "1.91:1"},
    "facebook": {"width": 1200, "height": 630, "aspect": "1.91:1"},
    "twitter": {"width": 1200, "height": 675, "aspect": "16:9"},
}

Step 2: Build Content-Aware Templates

CONTENT_TYPES = {
    "quote": {
        "prompt_template": "Minimalist quote graphic with large text: '{text}'. Clean background using {brand_color}. Professional typography.",
        "max_text_length": 150
    },
    "statistic": {
        "prompt_template": "Bold statistic graphic showing '{text}'. Large number in {brand_color}. Clean data visualization style.",
        "max_text_length": 80
    },
    "tip": {
        "prompt_template": "Numbered tip graphic: '{text}'. Clean layout with {brand_color} accents. Professional, easy to read.",
        "max_text_length": 200
    },
    "announcement": {
        "prompt_template": "Announcement graphic: '{text}'. Celebratory but professional. {brand_color} as primary color.",
        "max_text_length": 100
    }
}

def build_prompt(content_type, text, brand_config):
    template = CONTENT_TYPES[content_type]
    return template["prompt_template"].format(
        text=text[:template["max_text_length"]],
        brand_color=brand_config["colors"]["primary"]
    )

Step 3: Generate and Resize

from openai import OpenAI
from PIL import Image
import requests
from io import BytesIO

client = OpenAI()

def generate_social_image(content_type, text, platforms, brand_config):
    prompt = build_prompt(content_type, text, brand_config)
    response = client.images.generate(
        model="gpt-image-1",
        prompt=prompt,
        size="1024x1024",
        quality="high"
    )

    source_url = response.data[0].url
    resp = requests.get(source_url)
    source_img = Image.open(BytesIO(resp.content))

    outputs = {}
    for platform in platforms:
        spec = PLATFORM_SPECS[platform]
        resized = source_img.resize((spec["width"], spec["height"]), Image.LANCZOS)
        path = f"output/{platform}_{content_type}.png"
        resized.save(path)
        outputs[platform] = path

    return outputs

Step 4: Batch Generate a Content Calendar

def generate_weekly_content(content_plan, brand_config):
    all_outputs = []
    for day in content_plan:
        images = generate_social_image(
            content_type=day["type"],
            text=day["text"],
            platforms=day.get("platforms", ["instagram_feed", "linkedin"]),
            brand_config=brand_config
        )
        all_outputs.append({
            "day": day["day"],
            "text": day["text"],
            "images": images
        })
    return all_outputs

weekly_plan = [
    {"day": "Monday", "type": "tip", "text": "5 ways to automate your reporting this week"},
    {"day": "Wednesday", "type": "statistic", "text": "73% of businesses plan to increase AI spending in 2025"},
    {"day": "Friday", "type": "quote", "text": "The best time to automate was yesterday. The second best time is now."},
]

Step 5: Store and Organize

def save_to_library(content_type, text, image_paths, schedule_date=None):
    conn = sqlite3.connect("content_library.db")
    for platform, path in image_paths.items():
        conn.execute("""
            INSERT INTO social_images (content_type, text, platform, file_path, schedule_date, created_at)
            VALUES (?, ?, ?, ?, ?, datetime('now'))
        """, (content_type, text, platform, path, schedule_date))
    conn.commit()

What to Build Next

Connect to your social media scheduling tool. After images are generated and approved, push them directly to Buffer, Hootsuite, or your scheduling API with the post text. Full automation from content idea to scheduled post.

Related Reading

Want this system built for your business?

Get a free assessment. We will map every system your business needs and show you the ROI.

Get Your Free Assessment

Related Systems