I am doing a project in which i have to extract the important images from any website. Suppose we have following code :
<img src="/example/example.gif" width="40" height="40" />
From the above code we can easily find the image width and height using Jsoup Library. Now suppose we have following code :
<img src="/example/example.gif"/>
So, Is there any method to find the width and height of image without downloading that file.
Not without actually rendering the page or downloading the image. Even with
width = "40"
andheight = "40"
, you are only getting the value ofheight
andwidth
which may not be the dimensions of the actual image.The best way to do this would be to use something like PhantomJS, which is a headless webkit browser. You then will have to write a script that loads up the page (i.e., "renders" it by building up the DOM in memory) and then you can use the following code to get the actual height and width of the image: