<< More Tutorials
How to make an image responsive in Kotlin 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 Kotlin (we use Picturefill as polyfill):
object KotlinRethumbResponsiveExample {
@Throws(Exception::class)
@JvmStatic fun main(args: Array<String>) {
val imageUrl = "http://images.rethumb.com/image_coimbra_999x999.jpg"
val smallWidth = 400 // Image width for small resolutions (less than 400px).
val largeWidth = 800 // Image width for medium resolutions (less than 800px).
val imageWidth = 999 // Image original width (used for resolutions larger than 800px).
println("<script src=\"https://cdnjs.cloudflare.com/ajax/libs/picturefill/2.3.1/picturefill.min.js\"></script>\n" +
"\n" +
"<img src=\"http://api.rethumb.com/v1/width/" + smallWidth + "/" + imageUrl + "\"\n" +
"\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" +
"\n" +
" sizes=\"100vw\" />")
}
}
Start using this example now
Use the following commands to get started:
$ git clone https://github.com/rethumb/rethumb-kotlin-examples.git
$ cd rethumb-kotlin-examples
$ kotlinc responsive-images.kt -include-runtime -d responsive-images.jar
$ java -jar responsive-images.jar
More examples using Kotlin
How to use rethumb in Kotlin?
How to resize an image by width in Kotlin using rethumb?
How to resize an image by height in Kotlin using rethumb?
How to resize an image by width and height in Kotlin using rethumb?
How to create a square thumbnail from an image in Kotlin using rethumb?
How to read Exif data in json format from an image in Kotlin using rethumb?
How to make an image responsive in Kotlin using rethumb?
How to read GPS coordinates from an image in Kotlin using rethumb?
How to convert an image to JPG, GIF, PNG, TIF or WebP in Kotlin using rethumb?
How to resize an image to cover any dimensions in Kotlin using rethumb?