1

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.

TheLifeOfSteve
  • 3,208
  • 6
  • 37
  • 53
jackson
  • 21
  • 4
  • Possible duplicate: [Java/ImageIO Getting Image Dimension without reading the entire file?](http://stackoverflow.com/questions/1559253/java-imageio-getting-image-dimension-without-reading-the-entire-file) – Pshemo Jun 10 '15 at 19:02
  • Image contains informations about its width and high in its hearer (which can look different depending on image type) so all we need to do is download headers, we can ignore rest of image data. – Pshemo Jun 10 '15 at 19:08

1 Answers1

1

Not without actually rendering the page or downloading the image. Even with width = "40" and height = "40", you are only getting the value of height and width 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:

//assuming img is an image element
var width = img.clientWidth;
var height = img.clientHeight;
Vivin Paliath
  • 94,126
  • 40
  • 223
  • 295