views:

71

answers:

2

Given a URL how do I pull the largest image (in terms of image-dimensions) on the site? I am using it to act as the best possible representation of a sites thumbnail.

Similar to first thumbnail image when sharing a url on Facebook:

http://www.facebook.com/share.php?u=my_website_url

The image thumbnail on Facebook in the div:

<div class="UIThumbPager_Thumbs"> 

Current code (using Javascript and JQuery):

else if (item.link) historyHtml += '<a href=' + item.link + ' class="image" target="_blank"><img src="*SITE THUMBNAIL HERE*" width="111px"></a>';

Please note, the user will be logged in to Facebook and will be able to access that site thumbnail.

+1  A: 

"Largest" image in filesize or image-dimensions? You'll have to parse the URLs code, extract all images and get the size. If you mean the image-dimensions, you can do it with JavaScript (create a new image from the img-source and use img.width and img.height), but for the filesize, you'll probably end up downloading all images to determine which on is the largest.

Select0r
I mean the largest in terms of image-dimension. It gives the best representation of the site for a thumbnail. Or how about just pulling the Facebook thumbnail it generates for the URL for instance?
jprim
`just pulling the Facebook thumbnail it generates for the URL` ... ?? You may want to explain that in detail or (even better) put it in a separate question, as this seems to be something very different from your original question. Right now I don't really now what you're after.
Select0r
Sorry about that. I am looking to pull the site thumbnail generated on:http://www.facebook.com/share.php?u=my_website_urlWhen passing a URL through it (as described above using item.link).Please let me know if you have any other questions. Thank you!
jprim
Hopefully that answers your question.
jprim
It is always the image in <div class="UIThumbPager_Thumbs">
jprim
I can't open your URL as it needs a login and I'm not on facebook, but again: pull the source code, parse it and grab the image. Shouldn't be much of a problem as you know it's always in the same DIV. (And still: your question doesn't reflect what you're actually looking for)
Select0r
That is what I am asking to do. How do I pull the source code, parase it and grab the image? I updated the question, thanks.
jprim
+2  A: 

You can't do it on the client-side (i.e., with JavaScript) due to cross-domain restrictions. You'd need to download the contents of the URL on the back end first. See here: http://en.wikipedia.org/wiki/Same_origin_policy

Reinis I.
How about using getElementById("img")?
jprim
How is that going to work when your "img" is on a remote site?
Select0r
I think you mean `getElementsByTagName`, and that would still work only if the site was in the same domain.
Reinis I.
Oh ok, I did not realize it wouldn't work on a remote site.
jprim
@jprim you'll need a server side script acting as a proxy to do this.
Pekka
Hi Pekka, what if I just pull the image thumbnail Facebook creates for a URL as described above?
jprim