1

I am using Jsoup to get images of a web page.

Following is my code:

private String getImage(Document doc) {

        Elements images = doc.select("img[src~=(?i)\\.(png|jpe?g|gif)]");  
        String imgUrl = "";     

        for (Element image : images) {              
            imgUrl = image.attr("abs:src");
            break;
        }       
        return imgUrl;
}

Here I am getting first image of page, But I need image having max height or max width in page.

I can not use attr("height") as most of images does not have height and width attribute.

Can anyone help me how can I calculate height and width of images not having attribute height and width?

Thanks

Anupam Sharma
  • 1,529
  • 1
  • 14
  • 33
  • 3
    You need to get the image itself and have a look into it. A browser does the same when doing the layout and no rules for the size of an image element are given. – Hauke Ingmar Schmidt Apr 09 '15 at 09:26
  • @Hauke can I get page logo image? – Anupam Sharma Apr 09 '15 at 09:32
  • I don't understand that. Do you want to know how to get the favicon (the small icon in the URL bar, on tabs in the browser, or used for bookmarks)? – Hauke Ingmar Schmidt Apr 09 '15 at 09:51
  • No I want to get Logo Image of url page – Anupam Sharma Apr 09 '15 at 09:52
  • Your question is unclear: "I need image having max height or max width" what does this image have to do with logo? Anyway you should probably read http://stackoverflow.com/q/1559253/1393766 to see how to get width and hight of image without having to download its entire content. – Pshemo Apr 09 '15 at 10:36

0 Answers0