image-resolver

A Java 8 library to extract main image from a URL or HTML

License

License

Apache
GroupId

GroupId

com.shekhargulati
ArtifactId

ArtifactId

image-resolver
Last Version

Last Version

0.1.0
Release Date

Release Date

Type

Type

jar
Description

Description

image-resolver
A Java 8 library to extract main image from a URL or HTML
Project URL

Project URL

https://github.com/shekhargulati/image-resolver
Source Code Management

Source Code Management

https://github.com/shekhargulati/image-resolver.git

Download image-resolver

How to add to project

<!-- https://jarcasting.com/artifacts/com.shekhargulati/image-resolver/ -->
<dependency>
    <groupId>com.shekhargulati</groupId>
    <artifactId>image-resolver</artifactId>
    <version>0.1.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.shekhargulati/image-resolver/
implementation 'com.shekhargulati:image-resolver:0.1.0'
// https://jarcasting.com/artifacts/com.shekhargulati/image-resolver/
implementation ("com.shekhargulati:image-resolver:0.1.0")
'com.shekhargulati:image-resolver:jar:0.1.0'
<dependency org="com.shekhargulati" name="image-resolver" rev="0.1.0">
  <artifact name="image-resolver" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.shekhargulati', module='image-resolver', version='0.1.0')
)
libraryDependencies += "com.shekhargulati" % "image-resolver" % "0.1.0"
[com.shekhargulati/image-resolver "0.1.0"]

Dependencies

compile (3)

Group / Artifact Type Version
com.squareup.okhttp3 : okhttp jar 3.5.0
org.jsoup : jsoup jar 1.10.2
org.slf4j : slf4j-api jar 1.7.22

test (3)

Group / Artifact Type Version
junit : junit jar 4.12
org.assertj : assertj-core jar 3.6.2
org.slf4j : slf4j-simple jar 1.7.22

Project Modules

There are no modules declared in this project.

image-resolver Build Status codecov.io License

A Java 8 library to extract main image from a URL. Getting Started

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')

Using the API

It is very easy to use the API.

Extracting image from URL.

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")

Extracting image from HTML

Optional<String> mainImage = MainImageResolver.resolveMainImageFromHtml(html)

Extracting image using your HTML fetcher

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);

Inspiration

This library is inspired by Maurice Svay ImageResolver JavaScript library.

Versions

Version
0.1.0