Reputation: 1
I have developed almost all the functionality for having a preview of a web-page, just like facebook does. I use .net hhtprequest and then Html Agility Pack to parse the html and get the nodes and everything. But when it comes to finding the images that are larger than say 100pixels, I try to get the width attribute of image tag, if not i get the style attribute and find the width property, but sometimes the width comes from a css class and other times there is no width information. How can I get my server to load the images and find it out. But that will also cause a lot of load on the server, but any leads will be greatly appreciated. Thx in advance
Upvotes: 0
Views: 1086
Reputation: 27441
You can load image from URL:
int width = 0;
int height = 0;
WebClient client = new WebClient();
using(Stream stream = client.OpenRead(imageUrl))
using(Image image = Image.FromStream(stream))
{
width = image.Width;
height = image.Height;
}
The downfall being that you are making an additional HTTP request for every image you encounter that doesn't have dimensions set in HTML or CSS.
Upvotes: 2