docx-templates-5-image-insertion
Sub-skill of docx-templates: 5. Image Insertion.
Best use case
docx-templates-5-image-insertion is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Sub-skill of docx-templates: 5. Image Insertion.
Teams using docx-templates-5-image-insertion should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/5-image-insertion/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How docx-templates-5-image-insertion Compares
| Feature / Agent | docx-templates-5-image-insertion | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Sub-skill of docx-templates: 5. Image Insertion.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# 5. Image Insertion
## 5. Image Insertion
**Adding Images to Templates:**
```python
"""
Insert images into templates with proper sizing.
"""
from docxtpl import DocxTemplate, InlineImage
from docx.shared import Mm, Inches, Cm
from pathlib import Path
from typing import Optional, Union
from io import BytesIO
import requests
def add_image_to_template(
template_path: str,
output_path: str,
image_path: str,
context: dict,
width: Optional[Union[Mm, Inches, Cm]] = None,
height: Optional[Union[Mm, Inches, Cm]] = None
) -> None:
"""
Add an image to a template.
Template syntax:
{{ image }}
Args:
template_path: Path to template
output_path: Path for output
image_path: Path to image file
context: Additional context data
width: Image width (optional)
height: Image height (optional)
"""
template = DocxTemplate(template_path)
# Create InlineImage
image = InlineImage(
template,
image_path,
width=width,
height=height
)
# Add image to context
context["image"] = image
template.render(context)
template.save(output_path)
def add_image_from_url(
template: DocxTemplate,
url: str,
width: Optional[Mm] = None
) -> InlineImage:
"""
Create InlineImage from URL.
Args:
template: DocxTemplate instance
url: Image URL
width: Desired width
Returns:
InlineImage object
"""
response = requests.get(url)
response.raise_for_status()
image_stream = BytesIO(response.content)
return InlineImage(
template,
image_stream,
width=width
)
def render_document_with_images(
template_path: str,
output_path: str,
data: dict,
images: dict
) -> None:
"""
Render document with multiple images.
Template:
Company Logo: {{ logo }}
Product Images:
{% for product in products %}
{{ product.name }}: {{ product.image }}
{% endfor %}
"""
template = DocxTemplate(template_path)
# Process images
context = data.copy()
for key, image_info in images.items():
if isinstance(image_info, str):
# Simple path
context[key] = InlineImage(template, image_info, width=Mm(50))
elif isinstance(image_info, dict):
# Dict with path and dimensions
context[key] = InlineImage(
template,
image_info["path"],
width=image_info.get("width"),
height=image_info.get("height")
)
template.render(context)
template.save(output_path)
class ImageHandler:
"""
Handle images for template rendering.
"""
def __init__(self, template: DocxTemplate):
self.template = template
self._images: dict = {}
def add_image(
self,
key: str,
source: Union[str, BytesIO],
width: Optional[int] = None,
height: Optional[int] = None,
unit: str = "mm"
) -> 'ImageHandler':
"""
Add an image to the handler.
Args:
key: Context key for the image
source: File path or BytesIO stream
width: Width in specified units
height: Height in specified units
unit: Unit type ('mm', 'inches', 'cm')
"""
# Convert units
if unit == "mm":
w = Mm(width) if width else None
h = Mm(height) if height else None
elif unit == "inches":
w = Inches(width) if width else None
h = Inches(height) if height else None
elif unit == "cm":
w = Cm(width) if width else None
h = Cm(height) if height else None
else:
w = h = None
self._images[key] = InlineImage(
self.template,
source,
width=w,
height=h
)
return self
def add_image_from_url(
self,
key: str,
url: str,
width: int = 50,
unit: str = "mm"
) -> 'ImageHandler':
"""Add image from URL."""
response = requests.get(url)
response.raise_for_status()
image_stream = BytesIO(response.content)
return self.add_image(key, image_stream, width=width, unit=unit)
def get_context(self) -> dict:
"""Get images as context dictionary."""
*Content truncated — see parent skill for full reference.*Related Skills
stable-diffusion-image-generation
State-of-the-art text-to-image generation with Stable Diffusion models via HuggingFace Diffusers. Use when generating images from text prompts, performing image-to-image translation, inpainting, or building custom diffusion pipelines.
python-docx
Create and manipulate Microsoft Word documents programmatically. Build reports, contracts, and documentation with full control over paragraphs, tables, headers, styles, and images.
docx-templates
Template-based Word document generation using Jinja2 syntax. Create reports, contracts, and documents with loops, conditionals, tables, and mail merge capabilities.
docx
Comprehensive Word document toolkit for reading, creating, and editing .docx files. Supports text extraction, document creation with python-docx, and tracked changes via redlining workflow. Use for legal, academic, or professional document manipulation.
docker-1-image-optimization
Sub-skill of docker: 1. Image Optimization (+4).
n8n-8-workflow-templates-and-subworkflows
Sub-skill of n8n: 8. Workflow Templates and Subworkflows.
orcaflex-visualization-image-outputs
Sub-skill of orcaflex-visualization: Image Outputs (+1).
github-swarm-pr-1-pr-templates-for-swarm
Sub-skill of github-swarm-pr: 1. PR Templates for Swarm.
github-swarm-issue-issue-templates-for-swarms
Sub-skill of github-swarm-issue: Issue Templates for Swarms.
github-swarm-issue-1-issue-templates
Sub-skill of github-swarm-issue: 1. Issue Templates (+3).
pandoc-5-custom-latex-templates
Sub-skill of pandoc: 5. Custom LaTeX Templates (+1).
pandoc-2-image-management
Sub-skill of pandoc: 2. Image Management (+2).