[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M737WRHN0444SJCCQTNCWATS":3,"skill-same:01M737WRHN0444SJCCQTNCWATS":59},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":15,"categories":16,"keywords":17,"publishedAt":18,"linkOnly":19,"markdownContent":20,"markdownBody":21,"frontMatter":22,"refName":37,"commitSha":38,"skillDirectory":39,"forksCount":40,"repositoryHtmlUrl":41,"repositoryHomepageUrl":6,"ownerHtmlUrl":42,"ownerBlogUrl":43,"ownerDescription":6,"updatedAt":44,"install":45,"resources":58},"01M737WRHN0444SJCCQTNCWATS","create-2d-composition",null,"Compose 2D graphics programmatically using SVG generation, diagram layout algorithms, image compositing, and batch processing workflows. Use when generating diagrams, flowcharts, or infographics programmatically, creating reproducible scientific figures, automating production of badges or visual assets, building custom chart types not in standard libraries, or batch generating graphics with parameter variations.","roohe\u002Fagentic-super-skills","roohe","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F99054084?v=4","01M734WCDFP6RZVT5CNM00QR26","01M734WCE4BD0T4NZS5PCV9V5F",10,"MIT","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fcreate-2d-composition\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: create-2d-composition\nlocale: caveman-lite\nsource_locale: en\nsource_commit: 82c77053\ntranslator: \"Julius Brussee homage — caveman\"\ntranslation_date: \"2026-04-19\"\ndescription: >\n  Compose 2D graphics programmatically using SVG generation, diagram layout\n  algorithms, image compositing, and batch processing workflows. Use when\n  generating diagrams, flowcharts, or infographics programmatically, creating\n  reproducible scientific figures, automating production of badges or visual\n  assets, building custom chart types not in standard libraries, or batch\n  generating graphics with parameter variations.\nlicense: MIT\nallowed-tools: Read Write Edit Bash Grep Glob\nmetadata:\n  author: Philipp Thoss\n  version: \"1.0\"\n  domain: visualization\n  complexity: intermediate\n  language: Python\n  tags: svg, 2d, graphics, composition, diagrams, scripting, batch-processing\n---\n\n# Create 2D Composition\n\nGenerate 2D graphics programmatically using SVG construction, diagram layout algorithms, image compositing, and batch processing workflows. Covers vector graphics generation, raster image manipulation, typography, and automated production of charts, diagrams, and infographics.\n\n## When to Use\n\n- Generating diagrams, flowcharts, or infographics programmatically\n- Creating reproducible scientific figures or publication graphics\n- Automating production of badges, icons, or visual assets\n- Compositing multiple images or data visualizations\n- Building custom chart types not available in standard libraries\n- Batch generating graphics with parameter variations\n- Creating SVG templates for web or print applications\n\n## Inputs\n\n| Input | Type | Description | Example |\n|-------|------|-------------|---------|\n| Layout specification | Configuration | Dimensions, margins, grid layout | Canvas 800x600px, 20px margins |\n| Visual elements | Data\u002FAssets | Shapes, text, images, data points | Rectangle coordinates, labels, icons |\n| Style parameters | CSS\u002FAttributes | Colors, fonts, stroke widths, opacity | `fill=\"#3366cc\"`, `stroke-width=\"2\"` |\n| Data sources | Files\u002FArrays | Values to visualize or annotate | CSV data, JSON configuration |\n| Output format | String | SVG, PNG, PDF, composite formats | `output.svg`, 300 DPI PNG |\n\n## Procedure\n\n### 1. Set Up Python Environment\n\nInstall required libraries for 2D composition:\n\n```bash\n# Core libraries\npip install svgwrite pillow cairosvg\n\n# Optional: advanced features\npip install drawsvg reportlab pycairo\n\n# For data-driven graphics\npip install matplotlib numpy pandas\n```\n\n**Got:** Libraries installed successfully\n**If fail:** Check Python version (3.7+), use virtual environment to avoid conflicts\n\n### 2. Create Basic SVG Graphics\n\nGenerate SVG using svgwrite:\n\n```python\nimport svgwrite\nfrom svgwrite import cm, mm\n\ndef create_basic_svg(output_path):\n    \"\"\"Create a simple SVG graphic.\"\"\"\n    # Initialize drawing (use mm for precise dimensions)\n    dwg = svgwrite.Drawing(output_path, size=('180mm', '120mm'), profile='full')\n\n    # Add background rectangle\n    dwg.add(dwg.rect(\n        insert=(0, 0),\n        size=('100%', '100%'),\n        fill='white'\n    ))\n\n    # Add shapes\n    dwg.add(dwg.circle(\n        center=(90*mm, 60*mm),\n        r=30*mm,\n        fill='lightblue',\n        stroke='navy',\n        stroke_width=2\n    ))\n\n    dwg.add(dwg.rect(\n        insert=(30*mm, 30*mm),\n        size=(60*mm, 40*mm),\n        fill='lightgreen',\n        stroke='darkgreen',\n        stroke_width=2,\n        rx=5,  # Rounded corners\n        ry=5\n    ))\n\n    # Add text\n    dwg.add(dwg.text(\n        'Example Graphic',\n        insert=(90*mm, 20*mm),\n        text_anchor='middle',\n        font_size='18pt',\n        font_family='Arial',\n        fill='black'\n    ))\n\n    dwg.save()\n    print(f\"Saved: {output_path}\")\n```\n\n**Got:** SVG file generated with shapes and text\n**If fail:** Check svgwrite version, verify output directory writable\n\n### 3. Build Diagrams with Layout Logic\n\nCreate structured diagrams with calculated positioning:\n\n```python\ndef create_flowchart(steps, output_path):\n    \"\"\"Generate a flowchart from list of steps.\"\"\"\n    dwg = svgwrite.Drawing(output_path, size=('800px', '600px'))\n\n    # Layout parameters\n    box_width = 120\n    box_height = 60\n    spacing_y = 100\n    start_x = 340\n    start_y = 50\n\n    for i, step in enumerate(steps):\n        y_pos = start_y + i * spacing_y\n\n        # Draw box\n        box = dwg.add(dwg.g(id=f'step_{i}'))\n\n        box.add(dwg.rect(\n            insert=(start_x, y_pos),\n            size=(box_width, box_height),\n            fill='lightblue',\n            stroke='navy',\n            stroke_width=2,\n            rx=5,\n            ry=5\n        ))\n\n        # Add text (wrapped if needed)\n        text_lines = wrap_text(step, max_width=16)\n        text_y = y_pos + box_height\u002F2 - (len(text_lines)-1) * 7\n\n        for j, line in enumerate(text_lines):\n            box.add(dwg.text(\n                line,\n                insert=(start_x + box_width\u002F2, text_y + j*14),\n                text_anchor='middle',\n                font_size='12pt',\n                font_family='Arial',\n                fill='black'\n            ))\n\n        # Draw arrow to next step\n        if i \u003C len(steps) - 1:\n            arrow_start_y = y_pos + box_height\n            arrow_end_y = y_pos + spacing_y\n\n            dwg.add(dwg.line(\n                start=(start_x + box_width\u002F2, arrow_start_y),\n                end=(start_x + box_width\u002F2, arrow_end_y),\n                stroke='black',\n                stroke_width=2,\n                marker_end=dwg.marker(\n                    id='arrow',\n                    viewBox='0 0 10 10',\n                    refX=5,\n                    refY=5,\n                    markerWidth=6,\n                    markerHeight=6,\n                    orient='auto'\n                )\n            ))\n\n    dwg.save()\n\ndef wrap_text(text, max_width=20):\n    \"\"\"Simple text wrapping.\"\"\"\n    words = text.split()\n    lines = []\n    current_line = []\n\n    for word in words:\n        test_line = ' '.join(current_line + [word])\n        if len(test_line) \u003C= max_width:\n            current_line.append(word)\n        else:\n            if current_line:\n                lines.append(' '.join(current_line))\n            current_line = [word]\n\n    if current_line:\n        lines.append(' '.join(current_line))\n\n    return lines\n```\n\n**Got:** Flowchart with connected boxes and arrows\n**If fail:** Adjust layout calculations, verify arrow marker definitions\n\n### 4. Composite Raster Images\n\nCombine multiple images using Pillow:\n\n```python\nfrom PIL import Image, ImageDraw, ImageFont, ImageFilter\nimport os\n\ndef composite_images(image_paths, output_path, layout='grid'):\n    \"\"\"Composite multiple images into single output.\"\"\"\n    # Load images\n    images = [Image.open(path) for path in image_paths]\n\n    if layout == 'grid':\n        # Calculate grid dimensions\n        n = len(images)\n        cols = int(n ** 0.5)\n        rows = (n + cols - 1) \u002F\u002F cols\n\n        # Get max dimensions\n        max_width = max(img.width for img in images)\n        max_height = max(img.height for img in images)\n\n        # Create composite canvas\n        canvas_width = cols * max_width\n        canvas_height = rows * max_height\n        composite = Image.new('RGB', (canvas_width, canvas_height), 'white')\n\n        # Paste images\n        for i, img in enumerate(images):\n            row = i \u002F\u002F cols\n            col = i % cols\n            x = col * max_width\n            y = row * max_height\n            composite.paste(img, (x, y))\n\n    elif layout == 'horizontal':\n        # Horizontal concatenation\n        total_width = sum(img.width for img in images)\n        max_height = max(img.height for img in images)\n        composite = Image.new('RGB', (total_width, max_height), 'white')\n\n        x_offset = 0\n        for img in images:\n            composite.paste(img, (x_offset, 0))\n            x_offset += img.width\n\n    elif layout == 'vertical':\n        # Vertical concatenation\n        max_width = max(img.width for img in images)\n        total_height = sum(img.height for img in images)\n        composite = Image.new('RGB', (max_width, total_height), 'white')\n\n        y_offset = 0\n        for img in images:\n            composite.paste(img, (0, y_offset))\n            y_offset += img.height\n\n    composite.save(output_path)\n    print(f\"Saved composite: {output_path}\")\n\ndef add_annotations(image_path, annotations, output_path):\n    \"\"\"Add text annotations to image.\"\"\"\n    img = Image.open(image_path)\n    draw = ImageDraw.Draw(img)\n\n    # Load font\n    try:\n        font = ImageFont.truetype(\"Arial.ttf\", 24)\n    except:\n        font = ImageFont.load_default()\n\n    for annotation in annotations:\n        text = annotation['text']\n        position = annotation['position']\n        color = annotation.get('color', 'black')\n\n        # Add text shadow for readability\n        shadow_offset = 2\n        draw.text(\n            (position[0] + shadow_offset, position[1] + shadow_offset),\n            text,\n            font=font,\n            fill='white'\n        )\n        draw.text(position, text, font=font, fill=color)\n\n    img.save(output_path)\n```\n\n**Got:** Composite image created with proper layout\n**If fail:** Check all input images exist, verify image modes compatible\n\n### 5. Generate Data-Driven Graphics\n\nCreate visualizations from data:\n\n```python\nimport numpy as np\n\ndef create_bar_chart_svg(data, labels, output_path):\n    \"\"\"Generate SVG bar chart from data.\"\"\"\n    dwg = svgwrite.Drawing(output_path, size=('600px', '400px'))\n\n    # Chart area\n    margin = 50\n    chart_width = 500\n    chart_height = 300\n    bar_spacing = 10\n\n    # Calculate bar dimensions\n    n_bars = len(data)\n    bar_width = (chart_width - (n_bars - 1) * bar_spacing) \u002F n_bars\n\n    # Scale data to fit chart\n    max_value = max(data)\n    scale = chart_height \u002F max_value\n\n    # Draw axes\n    dwg.add(dwg.line(\n        start=(margin, margin),\n        end=(margin, margin + chart_height),\n        stroke='black',\n        stroke_width=2\n    ))\n    dwg.add(dwg.line(\n        start=(margin, margin + chart_height),\n        end=(margin + chart_width, margin + chart_height),\n        stroke='black',\n        stroke_width=2\n    ))\n\n    # Draw bars\n    for i, (value, label) in enumerate(zip(data, labels)):\n        x = margin + i * (bar_width + bar_spacing)\n        bar_height = value * scale\n        y = margin + chart_height - bar_height\n\n        # Bar\n        dwg.add(dwg.rect(\n            insert=(x, y),\n            size=(bar_width, bar_height),\n            fill='steelblue',\n            stroke='navy',\n            stroke_width=1\n        ))\n\n        # Value label\n        dwg.add(dwg.text(\n            f'{value:.1f}',\n            insert=(x + bar_width\u002F2, y - 5),\n            text_anchor='middle',\n            font_size='10pt',\n            fill='black'\n        ))\n\n        # X-axis label\n        dwg.add(dwg.text(\n            label,\n            insert=(x + bar_width\u002F2, margin + chart_height + 20),\n            text_anchor='middle',\n            font_size='10pt',\n            fill='black'\n        ))\n\n    dwg.save()\n```\n\n**Got:** SVG bar chart with scaled data\n**If fail:** Handle edge cases (empty data, negative values), add validation\n\n### 6. Batch Generate Graphics\n\nAutomate creation of multiple graphics:\n\n```python\ndef batch_generate_badges(users, template_path, output_dir):\n    \"\"\"Generate badge for each user.\"\"\"\n    os.makedirs(output_dir, exist_ok=True)\n\n    for user in users:\n        output_path = os.path.join(output_dir, f\"{user['id']}_badge.svg\")\n\n        dwg = svgwrite.Drawing(output_path, size=('300px', '100px'))\n\n        # Background\n        dwg.add(dwg.rect(\n            insert=(0, 0),\n            size=('100%', '100%'),\n            fill='#3366cc',\n            rx=10,\n            ry=10\n        ))\n\n        # User name\n        dwg.add(dwg.text(\n            user['name'],\n            insert=(150, 40),\n            text_anchor='middle',\n            font_size='20pt',\n            font_weight='bold',\n            fill='white'\n        ))\n\n        # User role\n        dwg.add(dwg.text(\n            user['role'],\n            insert=(150, 70),\n            text_anchor='middle',\n            font_size='14pt',\n            fill='lightblue'\n        ))\n\n        dwg.save()\n        print(f\"Generated badge: {output_path}\")\n```\n\n**Got:** Individual graphic generated for each data item\n**If fail:** Check data structure, handle missing fields with defaults\n\n### 7. Convert SVG to Raster\n\nExport SVG to PNG\u002FPDF for various uses:\n\n```python\nimport cairosvg\n\ndef svg_to_png(svg_path, png_path, dpi=300):\n    \"\"\"Convert SVG to PNG with specified DPI.\"\"\"\n    # Calculate pixel dimensions from DPI\n    # Assuming A4 size as example\n    width_inches = 8.27\n    height_inches = 11.69\n\n    width_px = int(width_inches * dpi)\n    height_px = int(height_inches * dpi)\n\n    cairosvg.svg2png(\n        url=svg_path,\n        write_to=png_path,\n        output_width=width_px,\n        output_height=height_px\n    )\n    print(f\"Converted to PNG: {png_path}\")\n\ndef svg_to_pdf(svg_path, pdf_path):\n    \"\"\"Convert SVG to PDF.\"\"\"\n    cairosvg.svg2pdf(url=svg_path, write_to=pdf_path)\n    print(f\"Converted to PDF: {pdf_path}\")\n```\n\n**Got:** Raster output generated at specified resolution\n**If fail:** Install cairo system library if missing, check SVG validity\n\n## Validation Checklist\n\n- [ ] Graphics render correctly in target applications\n- [ ] Text is readable and properly positioned\n- [ ] Colors match specifications (check hex codes)\n- [ ] Dimensions appropriate for use case\n- [ ] SVG validates against standard (if required)\n- [ ] Raster exports have correct DPI\n- [ ] Layout adapts to data variations\n- [ ] Batch processing completes without errors\n- [ ] Output files organized logically\n- [ ] Code includes error handling\n\n## Pitfalls\n\n1. **Unit confusion**: SVG units (px, mm, cm) vs screen pixels vs print DPI\n2. **Text overflow**: Text exceeding shape boundaries, implement wrapping\n3. **Font availability**: System fonts may differ, embed or use web-safe fonts\n4. **Coordinate calculations**: Off-by-one errors in grid layouts; color format — SVG uses hex strings (`#rrggbb`), not tuples\n5. **SVG validity**: Check XML structure, close all tags; handle special characters and spaces in file paths\n6. **Memory usage**: Large batch operations may require chunking; maintain aspect ratio when resizing\n7. **Transparency**: PNG supports alpha, JPEG does not\n\n## Related Skills\n\n- **[render-publication-graphic](..\u002Frender-publication-graphic\u002FSKILL.md)**: Publication-specific output requirements\n- **[create-3d-scene](..\u002F..\u002Fblender\u002Fcreate-3d-scene\u002FSKILL.md)**: Similar programmatic approach for 3D\n- **[generate-quarto-report](..\u002F..\u002Freporting\u002Fgenerate-quarto-report\u002FSKILL.md)**: Integrating graphics into reports\n","# Create 2D Composition\n\nGenerate 2D graphics programmatically using SVG construction, diagram layout algorithms, image compositing, and batch processing workflows. Covers vector graphics generation, raster image manipulation, typography, and automated production of charts, diagrams, and infographics.\n\n## When to Use\n\n- Generating diagrams, flowcharts, or infographics programmatically\n- Creating reproducible scientific figures or publication graphics\n- Automating production of badges, icons, or visual assets\n- Compositing multiple images or data visualizations\n- Building custom chart types not available in standard libraries\n- Batch generating graphics with parameter variations\n- Creating SVG templates for web or print applications\n\n## Inputs\n\n| Input | Type | Description | Example |\n|-------|------|-------------|---------|\n| Layout specification | Configuration | Dimensions, margins, grid layout | Canvas 800x600px, 20px margins |\n| Visual elements | Data\u002FAssets | Shapes, text, images, data points | Rectangle coordinates, labels, icons |\n| Style parameters | CSS\u002FAttributes | Colors, fonts, stroke widths, opacity | `fill=\"#3366cc\"`, `stroke-width=\"2\"` |\n| Data sources | Files\u002FArrays | Values to visualize or annotate | CSV data, JSON configuration |\n| Output format | String | SVG, PNG, PDF, composite formats | `output.svg`, 300 DPI PNG |\n\n## Procedure\n\n### 1. Set Up Python Environment\n\nInstall required libraries for 2D composition:\n\n```bash\n# Core libraries\npip install svgwrite pillow cairosvg\n\n# Optional: advanced features\npip install drawsvg reportlab pycairo\n\n# For data-driven graphics\npip install matplotlib numpy pandas\n```\n\n**Got:** Libraries installed successfully\n**If fail:** Check Python version (3.7+), use virtual environment to avoid conflicts\n\n### 2. Create Basic SVG Graphics\n\nGenerate SVG using svgwrite:\n\n```python\nimport svgwrite\nfrom svgwrite import cm, mm\n\ndef create_basic_svg(output_path):\n    \"\"\"Create a simple SVG graphic.\"\"\"\n    # Initialize drawing (use mm for precise dimensions)\n    dwg = svgwrite.Drawing(output_path, size=('180mm', '120mm'), profile='full')\n\n    # Add background rectangle\n    dwg.add(dwg.rect(\n        insert=(0, 0),\n        size=('100%', '100%'),\n        fill='white'\n    ))\n\n    # Add shapes\n    dwg.add(dwg.circle(\n        center=(90*mm, 60*mm),\n        r=30*mm,\n        fill='lightblue',\n        stroke='navy',\n        stroke_width=2\n    ))\n\n    dwg.add(dwg.rect(\n        insert=(30*mm, 30*mm),\n        size=(60*mm, 40*mm),\n        fill='lightgreen',\n        stroke='darkgreen',\n        stroke_width=2,\n        rx=5,  # Rounded corners\n        ry=5\n    ))\n\n    # Add text\n    dwg.add(dwg.text(\n        'Example Graphic',\n        insert=(90*mm, 20*mm),\n        text_anchor='middle',\n        font_size='18pt',\n        font_family='Arial',\n        fill='black'\n    ))\n\n    dwg.save()\n    print(f\"Saved: {output_path}\")\n```\n\n**Got:** SVG file generated with shapes and text\n**If fail:** Check svgwrite version, verify output directory writable\n\n### 3. Build Diagrams with Layout Logic\n\nCreate structured diagrams with calculated positioning:\n\n```python\ndef create_flowchart(steps, output_path):\n    \"\"\"Generate a flowchart from list of steps.\"\"\"\n    dwg = svgwrite.Drawing(output_path, size=('800px', '600px'))\n\n    # Layout parameters\n    box_width = 120\n    box_height = 60\n    spacing_y = 100\n    start_x = 340\n    start_y = 50\n\n    for i, step in enumerate(steps):\n        y_pos = start_y + i * spacing_y\n\n        # Draw box\n        box = dwg.add(dwg.g(id=f'step_{i}'))\n\n        box.add(dwg.rect(\n            insert=(start_x, y_pos),\n            size=(box_width, box_height),\n            fill='lightblue',\n            stroke='navy',\n            stroke_width=2,\n            rx=5,\n            ry=5\n        ))\n\n        # Add text (wrapped if needed)\n        text_lines = wrap_text(step, max_width=16)\n        text_y = y_pos + box_height\u002F2 - (len(text_lines)-1) * 7\n\n        for j, line in enumerate(text_lines):\n            box.add(dwg.text(\n                line,\n                insert=(start_x + box_width\u002F2, text_y + j*14),\n                text_anchor='middle',\n                font_size='12pt',\n                font_family='Arial',\n                fill='black'\n            ))\n\n        # Draw arrow to next step\n        if i \u003C len(steps) - 1:\n            arrow_start_y = y_pos + box_height\n            arrow_end_y = y_pos + spacing_y\n\n            dwg.add(dwg.line(\n                start=(start_x + box_width\u002F2, arrow_start_y),\n                end=(start_x + box_width\u002F2, arrow_end_y),\n                stroke='black',\n                stroke_width=2,\n                marker_end=dwg.marker(\n                    id='arrow',\n                    viewBox='0 0 10 10',\n                    refX=5,\n                    refY=5,\n                    markerWidth=6,\n                    markerHeight=6,\n                    orient='auto'\n                )\n            ))\n\n    dwg.save()\n\ndef wrap_text(text, max_width=20):\n    \"\"\"Simple text wrapping.\"\"\"\n    words = text.split()\n    lines = []\n    current_line = []\n\n    for word in words:\n        test_line = ' '.join(current_line + [word])\n        if len(test_line) \u003C= max_width:\n            current_line.append(word)\n        else:\n            if current_line:\n                lines.append(' '.join(current_line))\n            current_line = [word]\n\n    if current_line:\n        lines.append(' '.join(current_line))\n\n    return lines\n```\n\n**Got:** Flowchart with connected boxes and arrows\n**If fail:** Adjust layout calculations, verify arrow marker definitions\n\n### 4. Composite Raster Images\n\nCombine multiple images using Pillow:\n\n```python\nfrom PIL import Image, ImageDraw, ImageFont, ImageFilter\nimport os\n\ndef composite_images(image_paths, output_path, layout='grid'):\n    \"\"\"Composite multiple images into single output.\"\"\"\n    # Load images\n    images = [Image.open(path) for path in image_paths]\n\n    if layout == 'grid':\n        # Calculate grid dimensions\n        n = len(images)\n        cols = int(n ** 0.5)\n        rows = (n + cols - 1) \u002F\u002F cols\n\n        # Get max dimensions\n        max_width = max(img.width for img in images)\n        max_height = max(img.height for img in images)\n\n        # Create composite canvas\n        canvas_width = cols * max_width\n        canvas_height = rows * max_height\n        composite = Image.new('RGB', (canvas_width, canvas_height), 'white')\n\n        # Paste images\n        for i, img in enumerate(images):\n            row = i \u002F\u002F cols\n            col = i % cols\n            x = col * max_width\n            y = row * max_height\n            composite.paste(img, (x, y))\n\n    elif layout == 'horizontal':\n        # Horizontal concatenation\n        total_width = sum(img.width for img in images)\n        max_height = max(img.height for img in images)\n        composite = Image.new('RGB', (total_width, max_height), 'white')\n\n        x_offset = 0\n        for img in images:\n            composite.paste(img, (x_offset, 0))\n            x_offset += img.width\n\n    elif layout == 'vertical':\n        # Vertical concatenation\n        max_width = max(img.width for img in images)\n        total_height = sum(img.height for img in images)\n        composite = Image.new('RGB', (max_width, total_height), 'white')\n\n        y_offset = 0\n        for img in images:\n            composite.paste(img, (0, y_offset))\n            y_offset += img.height\n\n    composite.save(output_path)\n    print(f\"Saved composite: {output_path}\")\n\ndef add_annotations(image_path, annotations, output_path):\n    \"\"\"Add text annotations to image.\"\"\"\n    img = Image.open(image_path)\n    draw = ImageDraw.Draw(img)\n\n    # Load font\n    try:\n        font = ImageFont.truetype(\"Arial.ttf\", 24)\n    except:\n        font = ImageFont.load_default()\n\n    for annotation in annotations:\n        text = annotation['text']\n        position = annotation['position']\n        color = annotation.get('color', 'black')\n\n        # Add text shadow for readability\n        shadow_offset = 2\n        draw.text(\n            (position[0] + shadow_offset, position[1] + shadow_offset),\n            text,\n            font=font,\n            fill='white'\n        )\n        draw.text(position, text, font=font, fill=color)\n\n    img.save(output_path)\n```\n\n**Got:** Composite image created with proper layout\n**If fail:** Check all input images exist, verify image modes compatible\n\n### 5. Generate Data-Driven Graphics\n\nCreate visualizations from data:\n\n```python\nimport numpy as np\n\ndef create_bar_chart_svg(data, labels, output_path):\n    \"\"\"Generate SVG bar chart from data.\"\"\"\n    dwg = svgwrite.Drawing(output_path, size=('600px', '400px'))\n\n    # Chart area\n    margin = 50\n    chart_width = 500\n    chart_height = 300\n    bar_spacing = 10\n\n    # Calculate bar dimensions\n    n_bars = len(data)\n    bar_width = (chart_width - (n_bars - 1) * bar_spacing) \u002F n_bars\n\n    # Scale data to fit chart\n    max_value = max(data)\n    scale = chart_height \u002F max_value\n\n    # Draw axes\n    dwg.add(dwg.line(\n        start=(margin, margin),\n        end=(margin, margin + chart_height),\n        stroke='black',\n        stroke_width=2\n    ))\n    dwg.add(dwg.line(\n        start=(margin, margin + chart_height),\n        end=(margin + chart_width, margin + chart_height),\n        stroke='black',\n        stroke_width=2\n    ))\n\n    # Draw bars\n    for i, (value, label) in enumerate(zip(data, labels)):\n        x = margin + i * (bar_width + bar_spacing)\n        bar_height = value * scale\n        y = margin + chart_height - bar_height\n\n        # Bar\n        dwg.add(dwg.rect(\n            insert=(x, y),\n            size=(bar_width, bar_height),\n            fill='steelblue',\n            stroke='navy',\n            stroke_width=1\n        ))\n\n        # Value label\n        dwg.add(dwg.text(\n            f'{value:.1f}',\n            insert=(x + bar_width\u002F2, y - 5),\n            text_anchor='middle',\n            font_size='10pt',\n            fill='black'\n        ))\n\n        # X-axis label\n        dwg.add(dwg.text(\n            label,\n            insert=(x + bar_width\u002F2, margin + chart_height + 20),\n            text_anchor='middle',\n            font_size='10pt',\n            fill='black'\n        ))\n\n    dwg.save()\n```\n\n**Got:** SVG bar chart with scaled data\n**If fail:** Handle edge cases (empty data, negative values), add validation\n\n### 6. Batch Generate Graphics\n\nAutomate creation of multiple graphics:\n\n```python\ndef batch_generate_badges(users, template_path, output_dir):\n    \"\"\"Generate badge for each user.\"\"\"\n    os.makedirs(output_dir, exist_ok=True)\n\n    for user in users:\n        output_path = os.path.join(output_dir, f\"{user['id']}_badge.svg\")\n\n        dwg = svgwrite.Drawing(output_path, size=('300px', '100px'))\n\n        # Background\n        dwg.add(dwg.rect(\n            insert=(0, 0),\n            size=('100%', '100%'),\n            fill='#3366cc',\n            rx=10,\n            ry=10\n        ))\n\n        # User name\n        dwg.add(dwg.text(\n            user['name'],\n            insert=(150, 40),\n            text_anchor='middle',\n            font_size='20pt',\n            font_weight='bold',\n            fill='white'\n        ))\n\n        # User role\n        dwg.add(dwg.text(\n            user['role'],\n            insert=(150, 70),\n            text_anchor='middle',\n            font_size='14pt',\n            fill='lightblue'\n        ))\n\n        dwg.save()\n        print(f\"Generated badge: {output_path}\")\n```\n\n**Got:** Individual graphic generated for each data item\n**If fail:** Check data structure, handle missing fields with defaults\n\n### 7. Convert SVG to Raster\n\nExport SVG to PNG\u002FPDF for various uses:\n\n```python\nimport cairosvg\n\ndef svg_to_png(svg_path, png_path, dpi=300):\n    \"\"\"Convert SVG to PNG with specified DPI.\"\"\"\n    # Calculate pixel dimensions from DPI\n    # Assuming A4 size as example\n    width_inches = 8.27\n    height_inches = 11.69\n\n    width_px = int(width_inches * dpi)\n    height_px = int(height_inches * dpi)\n\n    cairosvg.svg2png(\n        url=svg_path,\n        write_to=png_path,\n        output_width=width_px,\n        output_height=height_px\n    )\n    print(f\"Converted to PNG: {png_path}\")\n\ndef svg_to_pdf(svg_path, pdf_path):\n    \"\"\"Convert SVG to PDF.\"\"\"\n    cairosvg.svg2pdf(url=svg_path, write_to=pdf_path)\n    print(f\"Converted to PDF: {pdf_path}\")\n```\n\n**Got:** Raster output generated at specified resolution\n**If fail:** Install cairo system library if missing, check SVG validity\n\n## Validation Checklist\n\n- [ ] Graphics render correctly in target applications\n- [ ] Text is readable and properly positioned\n- [ ] Colors match specifications (check hex codes)\n- [ ] Dimensions appropriate for use case\n- [ ] SVG validates against standard (if required)\n- [ ] Raster exports have correct DPI\n- [ ] Layout adapts to data variations\n- [ ] Batch processing completes without errors\n- [ ] Output files organized logically\n- [ ] Code includes error handling\n\n## Pitfalls\n\n1. **Unit confusion**: SVG units (px, mm, cm) vs screen pixels vs print DPI\n2. **Text overflow**: Text exceeding shape boundaries, implement wrapping\n3. **Font availability**: System fonts may differ, embed or use web-safe fonts\n4. **Coordinate calculations**: Off-by-one errors in grid layouts; color format — SVG uses hex strings (`#rrggbb`), not tuples\n5. **SVG validity**: Check XML structure, close all tags; handle special characters and spaces in file paths\n6. **Memory usage**: Large batch operations may require chunking; maintain aspect ratio when resizing\n7. **Transparency**: PNG supports alpha, JPEG does not\n\n## Related Skills\n\n- **[render-publication-graphic](..\u002Frender-publication-graphic\u002FSKILL.md)**: Publication-specific output requirements\n- **[create-3d-scene](..\u002F..\u002Fblender\u002Fcreate-3d-scene\u002FSKILL.md)**: Similar programmatic approach for 3D\n- **[generate-quarto-report](..\u002F..\u002Freporting\u002Fgenerate-quarto-report\u002FSKILL.md)**: Integrating graphics into reports\n",{"name":5,"locale":23,"license":14,"metadata":24,"translator":31,"description":32,"allowed-tools":33,"source_commit":34,"source_locale":35,"translation_date":36},"caveman-lite",{"tags":25,"author":26,"domain":27,"version":28,"language":29,"complexity":30},"svg, 2d, graphics, composition, diagrams, scripting, batch-processing","Philipp Thoss","visualization","1.0","Python","intermediate","Julius Brussee homage — caveman","Compose 2D graphics programmatically using SVG generation, diagram layout algorithms, image compositing, and batch processing workflows. Use when generating diagrams, flowcharts, or infographics programmatically, creating reproducible scientific figures, automating production of badges or visual assets, building custom chart types not in standard libraries, or batch generating graphics with parameter variations.\n","Read Write Edit Bash Grep Glob","82c77053","en","2026-04-19","master","f483e54f3ad5f202a77d45f2e57f8d970b71195f","skills_library\u002Fcreate-2d-composition",2,"https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills","https:\u002F\u002Fgithub.com\u002Froohe","yoou.link","2026-05-19 15:56:07",{"source":8,"skillName":5,"commands":46,"prompt":56,"zipAvailable":57},[47,50,53],{"tool":48,"command":49},"npx","npx skills add roohe\u002Fagentic-super-skills --skill create-2d-composition",{"tool":51,"command":52},"bunx","bunx skills add roohe\u002Fagentic-super-skills --skill create-2d-composition",{"tool":54,"command":55},"pnpm","pnpm dlx skills add roohe\u002Fagentic-super-skills --skill create-2d-composition","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fcreate-2d-composition\u002FSKILL.md",true,[],[60,67,74,81,88,95],{"skillNo":61,"name":62,"nameZh":6,"description":63,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":64,"categories":65,"keywords":66,"publishedAt":18},"01M73D865CZME2FCMKA4PQM348","zarr-python","Chunked N-D arrays for cloud storage. Compressed arrays, parallel I\u002FO, S3\u002FGCS integration, NumPy\u002FDask\u002FXarray compatible, for large-scale scientific computing pipelines.","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fzarr-python\u002FSKILL.md",[],[],{"skillNo":68,"name":69,"nameZh":6,"description":70,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":18},"01M73D7Z64J4ABWZJD7P44XBBF","youtube-downloader","Download and process YouTube content for research. Use when: downloading competitor videos for analysis; extracting audio for podcasts; getting transcripts for content repurposing; archiving webinars; research content curation","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fyoutube-downloader\u002FSKILL.md",[],[],{"skillNo":75,"name":76,"nameZh":6,"description":77,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":18},"01M73D7K8778TGZV3GJFR3703D","yc-pitch-deck","Create a compelling startup pitch deck that follows the structure proven to raise billions from top investors. Master the YC and Sequoia formats that get founders funded. Use when: **Fundraising** to create investor pitch decks; **YC application** to structure your narrative; **Demo Day prep** to craft your 2-minute pitch; **Angel investors** to communicate your opportunity; **Partnership pitches** to structure compelling asks","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fyc-pitch-deck\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":18},"01M73D70KJSE0E8Z28YMNNRT04","x-twitter-scraper","Use when the user needs X (Twitter) data or confirmation-gated X actions through Xquik: tweet search, user lookup, follower extraction, media download, monitoring, webhooks, MCP, SDKs, posting, likes, DMs, and profile updates. Requires a Xquik API key. Never ask for X login material.","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fx-twitter-scraper\u002FSKILL.md",[],[],{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":18},"01M73D6ED01GV077R7K4NZNFZJ","write-vignette","Create R package vignettes using R Markdown or Quarto. Covers vignette setup, YAML configuration, code chunk options, building and testing, and CRAN requirements for vignettes. Use when adding a Getting Started tutorial, documenting complex workflows spanning multiple functions, creating domain-specific guides, or when CRAN submission requires user-facing documentation beyond function help pages.","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fwrite-vignette\u002FSKILL.md",[],[],{"skillNo":96,"name":97,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":6,"repositoryNo":12,"starsCount":13,"licenseSpdxId":14,"licenseFileUrl":6,"sourceHtmlUrl":99,"categories":100,"keywords":101,"publishedAt":18},"01M73D69YJR0BK3NFHE0CYG3EF","write-validation-documentation","Write IQ\u002FOQ\u002FPQ validation documentation for computerized systems in regulated environments. Covers protocols, reports, test scripts, deviation handling, and approval workflows. Use when validating R or other software for regulated use, preparing for a regulatory audit, documenting qualification of computing environments, or creating and updating validation protocols and reports for new or re-qualified systems.","https:\u002F\u002Fgithub.com\u002Froohe\u002Fagentic-super-skills\u002Fblob\u002Fmaster\u002Fskills_library\u002Fwrite-validation-documentation\u002FSKILL.md",[],[]]