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.
-
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
- Clone Repository
git clone https://github.com/5Asim/ThumbnailGenerator
cd ThumbnailGenerator- Install Dependencies
npm install express multer sharp fluent-ffmpeg uuid- Install FFmpeg
Download FFmpeg and either:- Add to system PATH, OR
- Update path in code (see
ffmpegPathinserver.js)
- Start Server
node server.js- Upload Image
curl -X POST -F "[email protected]" http://localhost:3000/upload/imageResponse:
{
"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"
}
}- Upload Video
curl -X POST -F "[email protected]" http://localhost:3000/upload/videoResponse:
{
"video": "http://localhost:3000/uploads/123456789.mp4",
"thumbnail": "http://localhost:3000/uploads/processed_thumb_550e8400.jpg"
}| 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 |
FFmpeg Errors
# Verify FFmpeg installation
ffmpeg -versionFile Permission Issues
# On Linux/Mac
chmod -R 755 uploadsCommon Fixes
- Ensure
uploadsdirectory exists and is writable - Check FFmpeg path matches your system setup
- Verify uploaded files < 25MB (Multer default)
- Review console logs for processing errors
Optimized for
✅ Content management systems
✅ Media-heavy applications
✅ Automated thumbnail pipelines