Free Trial
10 days, no credit_card

<< More Tutorials

How to make an image responsive in Node.js using rethumb?

The following code prints HTML with responsive images support. It's ready to use and defines three levels of resolution: 400px, 800px and original image.

Adapt and start using the following code in Node.js (we use Picturefill as polyfill):

var image_url = "";

var small_width = 400; // Image width for small resolutions (less than 400px).
var large_width = 800; // Image width for medium resolutions (less than 800px).
var image_width = 999; // Image original width (used for resolutions larger than 800px).

    '<script src=""></script>\n'+
    '<img src="'+small_width+'/'+image_url+'"\n'+
    '     srcset="'+small_width+'/'+image_url+' '+small_width+'w,\n'+
    '   '+large_width+'/'+image_url+' '+large_width+'w,\n'+
    '             '+image_url+' '+image_width+'w"\n'+
    '     sizes="100vw" />'

Start using this example now

Use the following commands to get started:

$ git clone
$ cd rethumb-nodejs-examples
$ node responsive-images.js

More examples using Node.js