<< More Tutorials
How to convert an image to JPG, GIF, PNG, TIF or WebP in Node.js using rethumb?
To convert an image to JPG, GIF, PNG, TIF or WebP in Node.js use the following code:
var http = require("http");
var fs = require("fs");
// First apply a square operation, then convert to PNG format.
var paramOperation1 = "square";
var paramValue1 = 100;
var paramOperation2 = "format";
var paramValue2 = "png"; // Other formats available: jpg, gif, tiff and webp.
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 format.js
More examples using Node.js
How to use rethumb in Node.js?
How to resize an image by width in Node.js using rethumb?
How to resize an image by height in Node.js using rethumb?
How to resize an image by width and height in Node.js using rethumb?
How to create a square thumbnail from an image in Node.js using rethumb?
How to read Exif data in json format from an image in Node.js using rethumb?
How to make an image responsive in Node.js using rethumb?
How to read GPS coordinates from an image in Node.js using rethumb?
How to convert an image to JPG, GIF, PNG, TIF or WebP in Node.js using rethumb?
How to resize an image to cover any dimensions in Node.js using rethumb?