开发者

Grab largest image on site given the URL

开发者 https://www.devze.com 2023-01-14 14:49 出处:网络
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.

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.


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


"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.

0

精彩评论

暂无评论...
验证码 换一张
取 消