Make thumbnails of images
thmb takes a source image path and a destination image path and the dimensions of your desired thumbnail.
The created thumbnail image will be a resized and cropped version of the original. If the destination image isn't the same aspect ratio of the original then it'll resize it to fit within the space and crop the remainder. e.g. if your source aspect ratio is wider than your destination aspect ratio then it'll first be resized to the desired height and then the overhanging width will be cropped.
The thumbnail will not be created if file destination file already exists and has a newer mtime than the source file. If you are planning on using this utility for different size thumbnails then you are advised to use the size in your destination path somewhere as thmb won't check the destination file size if it exists, only the last-modified-timestamp of the file.
thmb builds on:
thmb(src, dst, options, callback)
src is the source file path,
dst is the destination file path and
options contains your thumbnailing options.
callback function will be called with an error object if an error has occurred (such as the file not existing), the second argument in the case of a successful thumbnail creation, or an existing thumbnail that didn't need to be updated will be the dimensions of the source image (this happens to be what I needed on the callback but you're welcome to suggest alternative callback data).
Number, required) the height of the cropped image
Number, required) the width of the cropped image
String, optional, default:
'png') set to
'jpeg'to return a JPEG
Bufferor write a JPEG file.
Number, optional) used when creating a JPEG, a number between 1 (lowest quality) and 100 (highest quality).
By default, thmb will write a PNG file. You can change this by specifying the
'type' on your
options object. You can also adjust the JPEG quality with a
var thmb =
Send a pull request or file an issue & I'll gladly consider extensions if you have a use-case.
thmb is Copyright (c) 2013 Rod Vagg @rvagg and licensed under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.