To use image-resolver in your application, you have to add image-resolver
in your classpath. image-resolver is available on Maven Central so you just need to add dependency to your favorite build tool as show below.
For Apache Maven users, please add following to your pom.xml.
<dependencies>
<dependency>
<groupId>com.shekhargulati</groupId>
<artifactId>image-resolver</artifactId>
<version>0.1.0</version>
</dependency>
</dependencies>
Gradle users can add following to their build.gradle file.
compile(group: 'com.shekhargulati', name: 'image-resolver', version: '0.1.0')
It is very easy to use the API.
String url = "https://medium.com/the-mission/how-to-get-people-to-like-you-in-5-seconds-or-less-67e64cb91155#.tp52bdm6m";
Optional<String> mainImage = MainImageResolver.resolveMainImage(url);
// Return Optional("https://cdn-images-1.medium.com/max/1200/1*-yql2CobEo8rGLCZv2gOyw.jpeg")
Optional<String> mainImage = MainImageResolver.resolveMainImageFromHtml(html)
If you want to use your own way to fetch HTML then you can use.
Optional<String> mainImage = MainImageResolver.resolveMainImage(url, url -> fetchHtml(), ImageResolvers.webpageResolvers);
This library is inspired by Maurice Svay ImageResolver JavaScript library.