🚨 rethumb will shutdown on September 4th, 2021 🚨 (Twitter)

<< More Tutorials

How to create a square thumbnail from an image in Node.js using rethumb?

To create a square thumbnail in Node.js use the following code:

var http = require("http");
var fs = require("fs");

var paramOperation = "square";
var paramValue = 100; // Square size in pixels.

var imageURL = "http://images.rethumb.com/image_coimbra_600x300.jpg";
var imageFilename = "resized-image.jpg";

http.get("http://api.rethumb.com/v1/" + paramOperation + "/" + paramValue + "/" + imageURL,
    function(response) {
        response.pipe(fs.createWriteStream(imageFilename));
    }
);

Start using this example now

Use the following commands to get started:

$ git clone https://github.com/rethumb/rethumb-nodejs-examples.git
$ cd rethumb-nodejs-examples
$ node resize-to-square.js

More examples using Node.js