open-thumbnailer
Overview
A friendly node.js JavaScript wrapper around phantomjs that lets you create webpage thumbnails in a headless environment with a few lines of code. There are generally several things you want to do when creating a thumbnail:
- Render the webpage as a PNG or JPG
- Control the quality level of your saved thumbnail (for JPGs)
- Resize the thumbnail
- Crop the thumbnail
- Copy / Delete / Rename thumbnails
The open-thumbnailer library makes all of this very easy.
Installation
npm install open-thumbnailer
To use a lot of the functionality in the library you will need to install graphicsmagick as well.
Examples Thumbnails
Here are some example thumbnails generated by this library:
To see some more thumbnails, look in the examples/thumbs directory. You can run the examples/top.js example and generate these thumbs for yourself.
Thumnailer Examples
Supported File Formats
You can save thumbnails as PNG of JPG files. For JPG files you can also specify a quality value in the fromUrl options that affects the JPG quality.
To create a thumbnail it's really just a few lines of code. For example to create a thumbnail for www.imdb.com you would do:
var OT = thumbnailer = ; thumbnailer;
At any point you can cancel an in progress thumbnail
thumbnailer.cancel();
There are various options you can specify to the thumbnailer when creating a thumb:
var OT = thumbnailer = ; thumbnailer;
Thumbnail Examples
Once you have generated a thumbnail, you will have a Thumbnail instance, there are several methods available to you:
getInfo -> returns basic information about the thumbnail
var info = thumb;console;
destroy -> deletes the thumbnail from the disk
thumb;
copy -> creates a copy of the thumbnail on disk
thumb;
move -> moves the thumbnail on disk
thumb;
resize -> resizes and potentially crops the thumbnail
thumb;
Development
- Install GraphicsMagick http://www.graphicsmagick.org/ (sudo port install graphicsmagick)
git clone https://github.com/markdaws/open-thumbnailer.gitcd open-thumbnailernpm installnpm test node examples/top.js