Skip to content

5Asim/ThumbnailGenerator

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Thumbnail Generator API

A Node.js API for generating image and video thumbnails using Sharp and FFmpeg. Handles file uploads, processes media files, and generates optimized thumbnails with automatic cleanup.

Features

  • Image Thumbnails
    Generate small (150px), medium (300px), and large (600px) JPEG thumbnails with:

    • Smart cropping based on attention area
    • Image quality optimization (MozJPEG)
    • Color enhancements (saturation + brightness)
  • Video Thumbnails
    Extract frames from videos (MP4/MKV/AVI) and:

    • Generate 320x180 processed thumbnails
    • Apply sharpening and color corrections
    • Automatic temporary file cleanup
  • Core Technologies

    • 🖼️ Sharp for image processing
    • 🎥 FFmpeg for video frame extraction
    • 📁 Multer for file upload handling
    • ♻️ Retry-based file cleanup system

Installation

  1. Clone Repository
git clone https://github.com/5Asim/ThumbnailGenerator
cd ThumbnailGenerator
  1. Install Dependencies
npm install express multer sharp fluent-ffmpeg uuid
  1. Install FFmpeg
    Download FFmpeg and either:
    • Add to system PATH, OR
    • Update path in code (see ffmpegPath in server.js)

Usage

  1. Start Server
node server.js
  1. Upload Image
curl -X POST -F "[email protected]" http://localhost:3000/upload/image

Response:

{
  "original": "http://localhost:3000/uploads/123456789.jpg",
  "thumbnails": {
    "small": "http://localhost:3000/uploads/thumb_small_123456789.jpg",
    "medium": "http://localhost:3000/uploads/thumb_medium_123456789.jpg",
    "large": "http://localhost:3000/uploads/thumb_large_123456789.jpg"
  }
}
  1. Upload Video
curl -X POST -F "[email protected]" http://localhost:3000/upload/video

Response:

{
  "video": "http://localhost:3000/uploads/123456789.mp4",
  "thumbnail": "http://localhost:3000/uploads/processed_thumb_550e8400.jpg"
}

Configuration

Setting Location Description
Upload Directory storage.destination Change via Multer config
Allowed Video Types allowedTypes array Modify in fileFilter
Thumbnail Sizes sizes object Adjust width values
FFmpeg Path ffmpegPath variable Set to your FFmpeg binary location

Troubleshooting

FFmpeg Errors

# Verify FFmpeg installation
ffmpeg -version

File Permission Issues

# On Linux/Mac
chmod -R 755 uploads

Common Fixes

  1. Ensure uploads directory exists and is writable
  2. Check FFmpeg path matches your system setup
  3. Verify uploaded files < 25MB (Multer default)
  4. Review console logs for processing errors

Optimized for
✅ Content management systems
✅ Media-heavy applications
✅ Automated thumbnail pipelines

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published