Alejandro Veintimilla
Alejandro Veintimilla

Reputation: 11523

How to bring image from url

When you share a link on Facebook, it displays an image from that webpage. How can I add that functionality to a forum I have?. I use django (but I am not sure if this matters).

Upvotes: 1

Views: 89

Answers (3)

Tony
Tony

Reputation: 1463

There is an API called thumbalizr. https://api.thumbalizr.com/

It's quite simple to use, you give it the URL and the width of the img. It gets you the thumbnail.

I bet there's many similar tools, but this seems to be one of the most popular.

EDIT:

  1. Write a script which would add your desired URL to this link https://api.thumbalizr.com/?url=URL_HERE
  2. Get screenshot capture status using HTTP header (X-Thumbalizr-Status) from the link you just created.
  3. According to it's status show the screenshot or show that it's still loading in your UI.

Upvotes: 1

Brian Stephens
Brian Stephens

Reputation: 5261

Here's a good article explaining a sample algorithm for finding the "best" image to represent an external webpage. It checks for the OG (Open Graph) tags that @petkostas mentioned, if the external page happens to use them. Otherwise, it looks for images on its own.

https://tech.shareaholic.com/2012/11/02/how-to-find-the-image-that-best-respresents-a-web-page/

Upvotes: 3

petkostas
petkostas

Reputation: 7450

Facebook uses OG for sharing, use the image tag of OG in your template. https://developers.facebook.com/docs/opengraph/howtos/maximizing-distribution-media-content Use an empty block in your template:

{% block opengraph %}{% endblock opengraph %}

Upvotes: 0

Related Questions