Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get thumbnails from any URL in iOS?

In both chat apps, social apps have a feature, when we paste a link on text view it's giving us a thumbnail from that url, enter image description here

Is this possible to do in an iOS app. If it is how may I do this?

like image 776
codebot Avatar asked Mar 23 '16 08:03

codebot


People also ask

How do I get the thumbnail of a link?

Well, save file to your server using file_put_contents(), and then you can create thumbnail. you can't get thumbnail directly from url.

What is a thumbnail URL?

The local file URL of the thumbnail image for the item.

How do I get the video thumbnail in swift 5?

Swift code to generate thumbnail from video URL:let frameImg = UIImage(cgImage: img!)


2 Answers

I would parse html content and try to find links to .png, jpg etc files. Then check the resolution to exclude very small images or those specified as a background in css. As a result a user would get a list of filtered images like on the screenshot you attached.

As a parser you could use https://github.com/nolanw/HTMLReader

like image 167
Mobile Developer Avatar answered Sep 21 '22 16:09

Mobile Developer


Pages like Facebook use OpenGraph information from web pages to generate thumbnails for links. OpenGraph attributes describe the object presented on a web page. OpenGraph data is stored in meta tags, as shown in A.Krasniqi's answer:

<meta property="og:title" content="The Rock" />
<meta property="og:type" content="video.movie" />
<meta property="og:url" content="http://www.imdb.com/title/tt0117500/" />
<meta property="og:image" content="http://ia.media-imdb.com/images/rock.jpg" />

These meta tags have a prefix of og.

Basic OpenGraph attributes include:

  • og:title (The title of the object)
  • og:type (The type of the object, e.g. video.movie)
  • og:url (A permanent, canonical URL to this object)
  • og:image (An image representing the page)

Other tags include:

  • og:description (A description of the object)
  • og:video
  • og:audio

All OpenGraph parameters are documented here

To parse these, you can use NSXMLParser but others have implemented OpenGraph parsers. (Just google "iOS OpenGraph parser")

like image 39
Palle Avatar answered Sep 23 '22 16:09

Palle