How to create website thumbnail with wordpress

Sometimes, we often need a website thumbnail image to display. It is hard to create it if you do it yourself, Fortunately, there are some api to create it. Here we introduce wordpress website thumbnail api.

How to create website thumbnail with wordpress api?

The api is:https://s0.wordpress.com/mshots/v1/

This api need three parameters:

URL: The website url, it should be encode.
w: the thumbnail width
h: the thumbnail height, it is optional

Here is an example to create a website thumbnail with this api using php. you also can use a curl to send a http request header to get image data and save it.

How to get image data with curl using php?

<?php
$url="https://www.exampleinsight.com/";
$w = 500;
$h = 300;

$api = "https://s0.wordpress.com/mshots/v1/";
$thumbnail_url = $api.urlencode($url)."?w=".$w."&h=".$h;
$data=file_get_contents($thumbnail_url);
file_put_contents("website_thumbnail.png",$data);
?>