<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://nekos.life/api/v2/img/neko",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "Error #:" . $err;
} else {
$imgs = json_decode($response);
$image = $imgs->{'url'};
$imageData = base64_encode(file_get_contents($image));
echo '<!DOCTYPE html>
<html>
<body align = "center">
<h1>Random Anime Image</h1>
<figure>
<img src="data:image/jpeg;base64,'.$imageData.'" alt="Trulli" style="width:100%">
<figcaption>©️Justine Agcanas.</figcaption>
</body>
</html>';
}
?>