Skip to main content

Overview

The ThumbnailDesignerAgent generates eye-catching YouTube thumbnails optimized for high click-through rates. It uses Sharp for image processing and creates thumbnails with strategic text overlays, color schemes, and visual elements.

Constructor

db
Database
required
Database instance for storing thumbnail data
credentials
Credentials
required
Credentials manager for external services
const { ThumbnailDesignerAgent } = require('./agents/thumbnail-designer-agent');

const agent = new ThumbnailDesignerAgent(db, credentials);

Properties

templatesPath
string
Path to thumbnail template assets directory
logger
Logger
Logger instance for tracking thumbnail generation

Methods

initialize()

Initializes the agent and creates necessary directories.
return
Promise<boolean>
Returns true when initialization is complete
await agent.initialize();
// Creates data/thumbnail-templates and uploads/thumbnails directories

generateThumbnail(script)

Generates a complete, optimized thumbnail for a video script.
script
Object
required
Video script object
script.title
string
required
Video title
script.metadata.strategy
Object
Content strategy with contentType
return
Promise<Object>
Thumbnail data object
thumbnail.path
string
Path to optimized thumbnail file (JPEG, under 2MB)
thumbnail.concept
Object
Design concept with style, colors, elements
thumbnail.prompt
string
AI generation prompt used
thumbnail.dimensions
Object
Width and height (1280x720)
thumbnail.fileSize
number
File size in bytes
const script = {
  title: 'How to Master JavaScript in 30 Days',
  metadata: {
    strategy: {
      contentType: 'Tutorial',
      topic: 'JavaScript'
    }
  }
};

const thumbnail = await agent.generateThumbnail(script);

console.log(thumbnail);
// {
//   path: '/path/to/thumbnail_optimized_1234567890.jpg',
//   concept: {
//     title: 'How to Master JavaScript in 30 Days',
//     style: 'clean',
//     primaryText: 'MASTER',
//     secondaryText: 'STEP BY STEP',
//     colors: { primary: 'blue', secondary: 'white', accent: 'green' },
//     emotion: 'helpful',
//     composition: 'rule-of-thirds',
//     effects: { blur: false, vignette: false, glow: true, shadow: true, border: false }
//   },
//   dimensions: { width: 1280, height: 720 },
//   fileSize: 156789,
//   createdAt: '2026-03-05T10:00:00.000Z'
// }

generateConcept(script)

Generates thumbnail design concept based on content type.
script
Object
required
Video script object
return
Promise<Object>
Design concept object
concept.title
string
Shortened title for thumbnail (max 5 words)
concept.style
string
Visual style: clean, informative, numbered, comparative, or dramatic
concept.primaryText
string
Main text overlay (impact word or number)
concept.secondaryText
string
Supporting text overlay
concept.elements
Array<string>
Visual elements to include
concept.colors
Object
Color scheme with primary, secondary, and accent colors
concept.emotion
string
Emotional tone: helpful, curious, exciting, analytical, or intriguing
concept.composition
string
Layout composition style
concept.effects
Object
Visual effects to apply (blur, vignette, glow, shadow, border)
const concept = await agent.generateConcept(script);
// Content type-specific concepts:
// Tutorial: clean style, blue/white/green, educational elements
// Explainer: informative, purple/yellow/white, question marks
// List: numbered, red/yellow/black, countdown elements
// Review: comparative, orange/gray/white, rating stars
// Story: dramatic, dark blue/gold/white, emotional imagery

Thumbnail Concepts by Content Type

{
  style: 'clean',
  elements: ['step numbers', 'arrows', 'progress indicators'],
  colors: ['blue', 'white', 'green'],
  emotion: 'helpful'
}

createThumbnail(concept)

Creates base thumbnail image with gradient background.
concept
Object
required
Design concept from generateConcept()
return
Promise<string>
Path to base thumbnail PNG file
const basePath = await agent.createThumbnail(concept);
// Creates 1280x720 PNG with gradient background

addTextOverlay(imagePath, concept)

Adds text overlay to thumbnail image.
imagePath
string
required
Path to base thumbnail image
concept
Object
required
Design concept with primaryText and secondaryText
return
Promise<string>
Path to thumbnail with text overlay
const withText = await agent.addTextOverlay(basePath, concept);
// Adds large primary text (120px) and secondary text (60px)
// Includes shadow effect for readability

optimizeForYouTube(imagePath)

Optimizes thumbnail for YouTube specifications.
imagePath
string
required
Path to thumbnail image
return
Promise<string>
Path to optimized JPEG file
format
string
JPEG with progressive encoding
quality
number
90% quality, reduced to 80% if file exceeds 2MB
dimensions
Object
1280x720 (YouTube recommended size)
maxFileSize
number
2MB (YouTube limit)
const optimized = await agent.optimizeForYouTube(withTextPath);
// Ensures file is under 2MB limit
// JPEG format with high quality and progressive loading

generateABVariants(concept)

Generates multiple thumbnail variants for A/B testing.
concept
Object
required
Base design concept
return
Promise<Array<string>>
Array of paths to thumbnail variants
const variants = await agent.generateABVariants(concept);
// Returns 3 variants:
// 1. Different color scheme (swapped primary/secondary)
// 2. Alternative text
// 3. Centered composition

console.log(variants);
// [
//   '/path/to/variant1.png',
//   '/path/to/variant2.png',
//   '/path/to/variant3.png'
// ]

extractPrimaryText(title)

Extracts most impactful text from title.
title
string
required
Video title
return
string
Primary text for thumbnail (uppercase)
const primary = agent.extractPrimaryText('The Ultimate Guide to JavaScript');
// 'ULTIMATE' (found impact word)

const primary2 = agent.extractPrimaryText('Top 10 Tips for Beginners');
// '10' (found number)

const primary3 = agent.extractPrimaryText('Learn Python Quickly');
// 'LEARN' (first significant word)

formatThumbnailTitle(title)

Shortens title for thumbnail display.
title
string
required
Full video title
return
string
Shortened title (max 5 words)
const short = agent.formatThumbnailTitle('The Complete Ultimate Guide to JavaScript Programming');
// 'The Complete Ultimate Guide to...'

selectComposition()

Randomly selects a composition style.
return
string
Composition style: rule-of-thirds, centered, diagonal, golden-ratio, or symmetrical
const composition = agent.selectComposition();
// 'rule-of-thirds'

selectEffects()

Randomly selects visual effects to apply.
return
Object
Effects configuration object
const effects = agent.selectEffects();
// {
//   blur: false,
//   vignette: true,
//   glow: false,
//   shadow: true,  // Always true
//   border: false
// }

Usage Example

const { ThumbnailDesignerAgent } = require('./agents/thumbnail-designer-agent');
const fs = require('fs').promises;

const agent = new ThumbnailDesignerAgent(db, credentials);
await agent.initialize();

// Generate thumbnail from script
const script = {
  title: 'Master React Hooks in 15 Minutes',
  metadata: {
    strategy: {
      contentType: 'Tutorial'
    }
  }
};

const thumbnail = await agent.generateThumbnail(script);

console.log('Thumbnail generated:', thumbnail.path);
console.log('File size:', Math.round(thumbnail.fileSize / 1024), 'KB');
console.log('Primary text:', thumbnail.concept.primaryText);
console.log('Color scheme:', thumbnail.concept.colors);

// Generate A/B test variants
const variants = await agent.generateABVariants(thumbnail.concept);
console.log('Created', variants.length, 'variants for testing');

// Copy to final location
await fs.copyFile(thumbnail.path, './final-thumbnail.jpg');

YouTube Thumbnail Requirements

1280x720 pixels (16:9 aspect ratio) - YouTube’s recommended size
Under 2MB - automatically enforced by optimizeForYouTube()
JPEG recommended - PNG also supported but results in larger files
90% quality for best balance, reduced to 80% if file exceeds limit

Best Practices

The agent automatically adds text shadows for readability. Primary text is large (120px) and bold.
Use generateABVariants() to create multiple thumbnails and test which performs best with your audience.
Each content type has optimized colors and style. Tutorial thumbnails use educational blue/green, while list videos use attention-grabbing red/yellow.
Primary text is limited to one impactful word or number. Secondary text adds context but stays concise.
Track click-through rates and adjust concept generation based on what works for your audience.