Canvas & SVG Design
Create professional-grade visual compositions programmatically using the HTML Canvas and SVG APIs.
Technical Options
1. HTML Canvas (Raster-based)
Best for complex rendering, particle systems, pixel manipulation, and performance-heavy visual effects.
Core Setup:
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
canvas.width = 1200;
canvas.height = 630; // OG Image standard
Common Patterns:
- Layers: Draw multiple elements sequentially to create depth.
- Gradients:
ctx.createLinearGradient() or ctx.createRadialGradient().
- Masking:
ctx.globalCompositeOperation = 'source-atop'.
- Text:
ctx.font = 'bold 48px Inter', ctx.fillText().
2. SVG (Vector-based)
Best for sharp graphics, logos, icons, and illustrations that need to scale without quality loss.
Core Setup:
const svg = `
<svg width="1200" height="630" xmlns="http://www.w3.org/2000/svg">
<rect width="100%" height="100%" fill="#1a1a1a" />
<!-- elements go here -->
</svg>
`;
Common Patterns:
- Paths:
<path d="..." /> for complex shapes.
- Groups:
<g> for organization and transformation nesting.
- Filters:
<defs><filter id="blur">...</filter></defs> for effects.
Design Principles for Programmatic Design
1. Grid & Layout
- Use mathematical ratios (Golden Ratio, Rule of Thirds).
- Define margins and gutters as percentage of width/height.
- Ensure visual balance across the frame.
2. Color Systems
- Define a base color palette (see
brand-guidelines).
- Use HSL for easier mathematical manipulation (hue shifting, lightness variation).
- Implement programmatic contrast checking.
3. Typography
- Prioritize legibility.
- Define a clear hierarchy: Heading, Subheading, Meta, Body.
- Use programmatic spacing (kerning, line-height) consistent with the design scale.
Workflow
Step 1: Composition Planning
- Sketch the layout mathematically.
- Define the coordinate system (e.g., 0 to 100 on both axes).
- Identify key visual elements and their relationships.
Step 2: Implementation
- Implement the background and foundational shapes.
- Add gradients, textures, or secondary patterns.
- Layer in typography and primary visual assets.
- Apply final effects (noise, blur, drop shadows).
Step 3: Export
- Provide the self-contained HTML/JS or SVG code.
- Provide a preview command or a way to download the resulting PNG/SVG.
Example: OG Image Generator Template
// Mathematical layout for an OG Image
const w = 1200;
const h = 630;
const padding = w * 0.05;
// Draw Background
ctx.fillStyle = '#111';
ctx.fillRect(0, 0, w, h);
// Draw Accent Gradient
const grad = ctx.createLinearGradient(0, 0, w, h);
grad.addColorStop(0, '#3b82f6');
grad.addColorStop(1, '#8b5cf6');
ctx.fillStyle = grad;
ctx.beginPath();
ctx.roundRect(padding, padding, w - padding*2, h - padding*2, 20);
ctx.fill();
// Draw Title
ctx.fillStyle = '#fff';
ctx.font = 'bold 80px Inter';
ctx.fillText('Programmatic Design', padding * 2, h/2);
1---2name: canvas-design-23domain: creative4skill_type: skill5description: >-6 Creates visual designs using HTML Canvas or SVG APIs for banners, social media7 assets, posters, or UI components. Use when the user requests programmatic8 graphic design, visual composition, or custom image generation without using a9 photo editor. Do NOT use for photo realistic image generation or general web UI10 layouts unless it specifically requires canvas/SVG.11license: MIT12tags: [canvas, svg, graphic-design, programmatic-design, composition]13metadata:14 source: https://skillmd.com/skills/knuckles-team/canvas-design-215 version: '1.6.0'16 author: Genius17---1819# Canvas & SVG Design2021Create professional-grade visual compositions programmatically using the HTML Canvas and SVG APIs.2223---2425## Technical Options2627### 1. HTML Canvas (Raster-based)28Best for complex rendering, particle systems, pixel manipulation, and performance-heavy visual effects.2930**Core Setup:**31```javascript32const canvas = document.createElement('canvas');33const ctx = canvas.getContext('2d');34canvas.width = 1200;35canvas.height = 630; // OG Image standard36```3738**Common Patterns:**39- **Layers**: Draw multiple elements sequentially to create depth.40- **Gradients**: `ctx.createLinearGradient()` or `ctx.createRadialGradient()`.41- **Masking**: `ctx.globalCompositeOperation = 'source-atop'`.42- **Text**: `ctx.font = 'bold 48px Inter'`, `ctx.fillText()`.4344### 2. SVG (Vector-based)45Best for sharp graphics, logos, icons, and illustrations that need to scale without quality loss.4647**Core Setup:**48```javascript49const svg = `50<svg width="1200" height="630" xmlns="http://www.w3.org/2000/svg">51 <rect width="100%" height="100%" fill="#1a1a1a" />52 <!-- elements go here -->53</svg>54`;55```5657**Common Patterns:**58- **Paths**: `<path d="..." />` for complex shapes.59- **Groups**: `<g>` for organization and transformation nesting.60- **Filters**: `<defs><filter id="blur">...</filter></defs>` for effects.6162---6364## Design Principles for Programmatic Design6566### 1. Grid & Layout67- Use mathematical ratios (Golden Ratio, Rule of Thirds).68- Define margins and gutters as percentage of width/height.69- Ensure visual balance across the frame.7071### 2. Color Systems72- Define a base color palette (see `brand-guidelines`).73- Use HSL for easier mathematical manipulation (hue shifting, lightness variation).74- Implement programmatic contrast checking.7576### 3. Typography77- Prioritize legibility.78- Define a clear hierarchy: Heading, Subheading, Meta, Body.79- Use programmatic spacing (kerning, line-height) consistent with the design scale.8081---8283## Workflow8485### Step 1: Composition Planning86- Sketch the layout mathematically.87- Define the coordinate system (e.g., 0 to 100 on both axes).88- Identify key visual elements and their relationships.8990### Step 2: Implementation91- Implement the background and foundational shapes.92- Add gradients, textures, or secondary patterns.93- Layer in typography and primary visual assets.94- Apply final effects (noise, blur, drop shadows).9596### Step 3: Export97- Provide the self-contained HTML/JS or SVG code.98- Provide a preview command or a way to download the resulting PNG/SVG.99100---101102## Example: OG Image Generator Template103104```javascript105// Mathematical layout for an OG Image106const w = 1200;107const h = 630;108const padding = w * 0.05;109110// Draw Background111ctx.fillStyle = '#111';112ctx.fillRect(0, 0, w, h);113114// Draw Accent Gradient115const grad = ctx.createLinearGradient(0, 0, w, h);116grad.addColorStop(0, '#3b82f6');117grad.addColorStop(1, '#8b5cf6');118ctx.fillStyle = grad;119ctx.beginPath();120ctx.roundRect(padding, padding, w - padding*2, h - padding*2, 20);121ctx.fill();122123// Draw Title124ctx.fillStyle = '#fff';125ctx.font = 'bold 80px Inter';126ctx.fillText('Programmatic Design', padding * 2, h/2);127```