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

<< More Tutorials

How to make an image responsive in Java 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 Java (we use Picturefill as polyfill):

public class JavaRethumbExample
    public static void main(String [] args) throws Exception
        String imageUrl = "http://images.rethumb.com/image_coimbra_999x999.jpg";

        int smallWidth = 400; // Image width for small resolutions (less than 400px). 
        int largeWidth = 800; // Image width for medium resolutions (less than 800px).
        int imageWidth = 999; // Image original width (used for resolutions larger than 800px).

            "<script src=\"https://cdnjs.cloudflare.com/ajax/libs/picturefill/2.3.1/picturefill.min.js\"></script>\n"+
            "<img src=\"http://api.rethumb.com/v1/width/"+smallWidth+"/"+imageUrl+"\"\n"+
            "     srcset=\"http://api.rethumb.com/v1/width/"+smallWidth+"/"+imageUrl+" "+smallWidth+"w,\n"+
            "             http://api.rethumb.com/v1/width/"+largeWidth+"/"+imageUrl+" "+largeWidth+"w,\n"+
            "             "+imageUrl+" "+imageWidth+"w\"\n"+
            "     sizes=\"100vw\" />"

Start using this example now

Use the following commands to get started:

$ git clone https://github.com/rethumb/rethumb-java-examples.git
$ cd rethumb-java-examples
$ ... Use your IDE of choice to handle the file "responsive-images.java"

More examples using Java