PHP code example of ivkos / wallhaven

1. Go to this page and download the library: Download ivkos/wallhaven library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

ivkos / wallhaven example snippets




use Wallhaven\Category;
use Wallhaven\Order;
use Wallhaven\Purity;
use Wallhaven\Sorting;
use Wallhaven\Wallhaven;

$wh = new Wallhaven();

$wh = new Wallhaven('YOUR_USERNAME', 'YOUR_PASSWORD');

$wallpapers = $wh->filter()
	->keywords("#cars")
	->categories(Category::GENERAL)
	->purity(Purity::SFW)
	->sorting(Sorting::FAVORITES)
	->order(Order::DESC)
	->resolutions(["1920x1080", "2560x1440"])
	->ratios(["16x9"])
	->pages(3)
	->getWallpapers();

$wallpapers = $wh->filter()
	->keywords("landscape")
	->ratios(["16x9"])
	->pages(2)
	->getWallpapers();

// Get favorites count for the first wallpaper in the list
$wallpapers[0]->getFavorites();

// Print resolutions of all wallpapers in the list
foreach ($wallpapers as $w) {
	echo $w->getResolution() . PHP_EOL;
}

// Get the number of wallpapers in the list
echo "There are " . $wallpapers->count() . " wallpapers!" . PHP_EOL;

$w = $wh->wallpaper(198320);

$w->getTags();  // ["cats", "closeups"]
$w->getViews(); // int(3500)

$wallpapers = $wh->filter()->keywords(...)->getWallpapers();

$wallpapers[0]->getId();        // int(103929)
$wallpapers[0]->getFavorites(); // int(367)

$wh->wallpaper(198320)->download("/home/user/wallpapers");

$wallpapers = $wh->filter()->keywords(...)->getWallpapers();
$wallpapers->downloadAll("/home/user/wallpapers");

use Wallhaven\Wallhaven;
use Wallhaven\WallpaperList;

$wh = new Wallhaven();
$batch = new WallpaperList();
$batch[] = $wh->wallpaper(198320);
$batch[] = $wh->wallpaper(103929);

$batch->downloadAll("/home/user/wallpapers");