-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.php
39 lines (31 loc) · 1.08 KB
/
app.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
require 'vendor/autoload.php';
use \Aniwall\Service\WallhavenService;
$wallhaven = new WallhavenService();
// Get random title anime
$string = file_get_contents("config/list_anime.json");
$listAnime = json_decode($string, true);
$nb = rand(0, count($listAnime) - 1);
echo 'Name: '.$listAnime[$nb].PHP_EOL;
// Search all wallpaper in wallhaven
$res = $wallhaven->search($listAnime[$nb]);
if (!empty($res->getImages())) {
$images = $res->getImages();
// Get thumb from random wallpaper
$randWallpaper = rand(0, count($images) - 1);
echo $images[$randWallpaper]->getThumb().PHP_EOL;
// Get random wallpaper
$wallpaper = $wallhaven->get($images[$randWallpaper]->getId());
if ($wallpaper) {
echo 'Url image: '.$wallpaper->getFullImage().PHP_EOL;
// Get Tags
$tags = $wallpaper->getTags();
$stringTag = '';
foreach ($tags as $tag) {
$stringTag .= '#'.str_replace(' ', '', $tag->getText()).' ';
}
echo 'Tags: '.$stringTag.PHP_EOL;
}
} else {
echo 'No image found.'.PHP_EOL;
}