Free Trial
10 days, no credit_card

<< More Tutorials

How to resize an image by width and height in Node.js using rethumb?

To resize an image or photo in Node.js use the following code:

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

var paramOperation1 = "height";
var paramValue1 = 100; // New height in pixels.

var paramOperation2 = "width";
var paramValue2 = 100; // New width in pixels.

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

http.get("http://api.rethumb.com/v1/" + paramOperation1 + "/" + paramValue1 + "/" + paramOperation2 + "/" + paramValue2 + "/" + 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-by-width-and-height.js

More examples using Node.js