Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ivkos/wallhaven4php
Wallhaven API for PHP - Search, filter and download wallpapers
https://github.com/ivkos/wallhaven4php
Last synced: 4 days ago
JSON representation
Wallhaven API for PHP - Search, filter and download wallpapers
- Host: GitHub
- URL: https://github.com/ivkos/wallhaven4php
- Owner: ivkos
- License: mit
- Created: 2014-10-17T09:37:59.000Z (about 10 years ago)
- Default Branch: master
- Last Pushed: 2016-08-20T09:52:18.000Z (about 8 years ago)
- Last Synced: 2024-04-14T05:14:22.792Z (7 months ago)
- Language: PHP
- Homepage:
- Size: 35.2 KB
- Stars: 36
- Watchers: 4
- Forks: 6
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Wallhaven API for PHP
===================
[![](https://img.shields.io/packagist/v/ivkos/wallhaven.svg?style=flat-square)](https://packagist.org/packages/ivkos/wallhaven)
[![](https://img.shields.io/packagist/dt/ivkos/wallhaven.svg?style=flat-square)](https://packagist.org/packages/ivkos/wallhaven)
[![](https://img.shields.io/github/license/ivkos/Wallhaven.svg?style=flat-square)](LICENSE)## Description
A PHP library for **[Wallhaven](https://wallhaven.cc)** that allows you to search for wallpapers and get information
about them in convenient OOP syntax. Additionally, this library provides the ability to download individual
wallpapers, or batch download many wallpapers asynchronously which considerably reduces download times.## Requirements
* PHP 5.4 or newer
* Composer## Install
Create a `composer.json` file in your project root:
```json
{
"require": {
"ivkos/wallhaven": "2.*"
}
}
```Run `php composer.phar install` to download the library and its dependencies.
## Quick Documentation
Add this line to include Composer packages:
```php
filter()
->keywords("#cars")
->categories(Category::GENERAL)
->purity(Purity::SFW)
->sorting(Sorting::FAVORITES)
->order(Order::DESC)
->resolutions(["1920x1080", "2560x1440"])
->ratios(["16x9"])
->pages(3)
->getWallpapers();
``````php
$wallpapers = $wh->filter()
->keywords("landscape")
->ratios(["16x9"])
->pages(2)
->getWallpapers();
```
Returns a `WallpaperList` object containing `Wallpaper` objects that match the criteria above.The `WallpaperList` object can be accessed like an array, iterated over using `foreach`, and has a `WallpaperList::count()` method:
```php
// 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;
```### Wallpaper Information
The `Wallpaper` object has a number of methods that provide information about the wallpaper:- `getId()`
- `getTags()`
- `getPurity()`
- `getResolution()`
- `getSize()`
- `getCategory()`
- `getViews()`
- `getFavorites()`
- `getFeaturedBy()` - not accessible if not logged in
- `getFeaturedDate()` - not accessible if not logged in
- `getUploadedBy()`
- `getUploadedDate()`
- `getImageUrl()`
- `getThumbnailUrl()`You can get information about a single wallpaper if you know its ID:
```php
$w = $wh->wallpaper(198320);$w->getTags(); // ["cats", "closeups"]
$w->getViews(); // int(3500)
```You can also get information about wallpapers from a search result:
```php
$wallpapers = $wh->filter()->keywords(...)->getWallpapers();$wallpapers[0]->getId(); // int(103929)
$wallpapers[0]->getFavorites(); // int(367)
```### Downloading
To download a single wallpaper to a specific directory:
```php
$wh->wallpaper(198320)->download("/home/user/wallpapers");
```To batch download wallpapers from a search result:
```php
$wallpapers = $wh->filter()->keywords(...)->getWallpapers();
$wallpapers->downloadAll("/home/user/wallpapers");
```You can also create a `WallpaperList`, add specific wallpapers to it, and then batch download them, like so:
```php
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");
```#### For more information, please refer to the source code and the PHPDoc blocks.