Thumbd is an image thumbnailing server built on top of Node.js, SQS, S3, and ImageMagick.
You can easily run Thumbd on Heroku. Simply set the appropriate environment variables with config:set and deploy using the Procfile provided.
Note: Creating video thumbnails on Heroku requires use of custom ffmpeg buildpack. Please refer to Heroku deployment guide in Wiki.
apt-get install imagemagick
npm install thumbd
To install thumbd as a service:
npm install thumbd -g
thumbd install
thumbd start
Thumbd requires the following environment variables to be set:
us-east-1.convert.15000.private, or public-read. Defaults to private.STANDARD or REDUCED_REDUNDANCY. Defaults to STANDARD.When running locally, I set these environment variables in a .env file and execute thumbd using Foreman.
Additionally, the following environment variable can be set to use a custom logger:
LOGGER_FILE the path to a javascript file that exports the info, warn and error methods.
The thumbd server:
http:// or https://.BUCKET environment variable.[original filename excluding extension]_[thumbnail suffix].[thumbnail format]Assume that the following thumbnail job was received over SQS:
{
"original": "example.png",
"descriptions": [
{
"suffix": "tiny",
"width": 48,
"height": 48
},
{
"suffix": "small",
"width": 100,
"height": 100,
"background": "red"
},
{
"suffix": "medium",
"width": 150,
"height": 150,
"strategy": "bounded"
}
]
}
Once thumbd processes the job, the files stored in S3 will look something like this:
Submit thumbnailing jobs from your application by creating an instance of a thumbd client (contribute by submitting clients in other languages).
var Client = require('./thumbd').Client,
client = new Client({
awsKey: 'AWS-KEY',
awsSecret: 'AWS-SECRET',
awsRegion: 'AWS-REGION',
sqsQueue: 'thumbnailing-queue',
s3Bucket: 'thumbnails'
});
var destination = '/example/awesome.jpg';
client.upload('/tmp/awesome.jpg', destination, function(err) {
if (err) throw err;
client.thumbnail(destination, [{suffix: 'small', width: 100, height: 100, background: 'red', strategy: 'matted'}], {
notify: 'https://callback.example.com', // optional web-hook when processing is done.
prefix: 'foobar' // optional prefix for thumbnails created.
});
});
Thumbnailing options:
string or array, path to image or images that thumbnailing should be applied to.array describing the thumbnails that should be created.The descriptions received in the thumbnail job describe the way in which thumbnails should be generated.
description accepts the following keys:
jpg, gif, defaults to jpg.%(command)s -border 0 %(localPaths[0])s %(convertedPath)s90.Starting the server:
thumbd server --aws_key=<key> --aws_secret=<secret> --sqs_queue=<sqs queue name> --bucket=<s3 thumbnail bucket> [--aws_region=<region>] [--tmp_dir=</tmp>] [--s3_acl=<private or public-read>] [--s3_storage_class=<STANDARD or REDUCED_REDUNDANCY>]
Manually submitting an SQS thumbnailing job (useful for testing purposes):
thumbd thumbnail --remote_image=<path to image s3 or http> --descriptions=<path to thumbnail description JSON file> --aws_key=<key> --aws_secret=<secret> --sqs_queue=<sqs queue name> [--aws_region=<region>]
{
"resources": [
"images/image1.png",
"images/image2.png"
],
"descriptions": [{
"strategy": "%(command)s -border 0 -tile 2x1 -geometry 160x106 '%(localPaths[0])s' '%(localPaths[1])s' %(convertedPath)s",
"command": "montage",
"suffix": "stitch"
}]
}
Creating Video Thumbnails on Heroku
Creating video thumbnails on Heroku requires using custom buildpack. In short :
ffmpeg for thumbnail generation, rather than convert.For detailed instructions, please refer to Heroku deployment guide in Wiki.
The custom strategy can be used for a variety of purposes, experiment with it :tm:
At Attachments.me, thumbd thumbnailed tens of thousands of images a day. There are a few things you should know about our production deployment:
![]()
If you build something cool using thumbd let me know, I will list it here.
Copyright (c) 2015 Contributors, See LICENSE.txt for further details.