简体   繁体   中英

Fetch Images from URL - Like Facebook Thumbnail

I am building a "Reddit" like site.

The User can post an URL from which I want to get the correct image with PHP.

What I would need is a script which sites like Facebook or Tumblr use to fetch the Images. I saw already scripts which get the images by getting the HTML Content and searching for "img" tags.

Are there any better methods/scripts available?

Maybe even scripts which will order the images by the size: The bigger the image the more important it is.

Thanks for answers

You may want to check out PHPQuery , it will allow you easily iterate through all images on a given website. You can then work out the areas of each image and sort them accordingly.

It depends a bit for what you're looking for and what the image is that the user would like to have with his post. To give you an example: I once wrote a method that searches for a logo of a company on the company's website. To do so, I searched for, indeed, the img-tags using simple_html_dom and filtered those tags on the existence of logo in the alt-tag. The results are displayed to the user to select the right image; it could be that you find multiple images fitting your purpose.

I would indeed, as you proposed, have a look at the size and skip small images (eg smaller dan lets say 50 px).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM