{"id":19517492,"url":"https://github.com/ivkos/wallhaven4php","last_synced_at":"2025-08-23T01:04:58.195Z","repository":{"id":22024418,"uuid":"25350547","full_name":"ivkos/wallhaven4php","owner":"ivkos","description":"Wallhaven API for PHP - Search, filter and download wallpapers","archived":false,"fork":false,"pushed_at":"2016-08-20T09:52:18.000Z","size":36,"stargazers_count":36,"open_issues_count":0,"forks_count":6,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-14T11:04:51.870Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ivkos.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-10-17T09:37:59.000Z","updated_at":"2023-10-03T19:13:56.000Z","dependencies_parsed_at":"2022-08-20T14:40:37.770Z","dependency_job_id":null,"html_url":"https://github.com/ivkos/wallhaven4php","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/ivkos/wallhaven4php","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivkos%2Fwallhaven4php","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivkos%2Fwallhaven4php/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivkos%2Fwallhaven4php/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivkos%2Fwallhaven4php/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivkos","download_url":"https://codeload.github.com/ivkos/wallhaven4php/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivkos%2Fwallhaven4php/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271727460,"owners_count":24810561,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-22T02:00:08.480Z","response_time":65,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-11T00:04:09.941Z","updated_at":"2025-08-23T01:04:58.162Z","avatar_url":"https://github.com/ivkos.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"Wallhaven API for PHP\n===================\n[![](https://img.shields.io/packagist/v/ivkos/wallhaven.svg?style=flat-square)](https://packagist.org/packages/ivkos/wallhaven)\n[![](https://img.shields.io/packagist/dt/ivkos/wallhaven.svg?style=flat-square)](https://packagist.org/packages/ivkos/wallhaven)\n[![](https://img.shields.io/github/license/ivkos/Wallhaven.svg?style=flat-square)](LICENSE)\n\n## Description\nA PHP library for **[Wallhaven](https://wallhaven.cc)** that allows you to search for wallpapers and get information\nabout them in convenient OOP syntax. Additionally, this library provides the ability to download individual\nwallpapers, or batch download many wallpapers asynchronously which considerably reduces download times.\n\n## Requirements\n* PHP 5.4 or newer\n* Composer\n\n## Install\nCreate a `composer.json` file in your project root:\n```json\n{\n    \"require\": {\n        \"ivkos/wallhaven\": \"2.*\"\n    }\n}\n```\n\nRun `php composer.phar install` to download the library and its dependencies.\n\n## Quick Documentation\nAdd this line to include Composer packages:\n```php\n\u003c?php\nrequire 'vendor/autoload.php';\n```\n\nInitialize Wallhaven:\n```php\nuse Wallhaven\\Category;\nuse Wallhaven\\Order;\nuse Wallhaven\\Purity;\nuse Wallhaven\\Sorting;\nuse Wallhaven\\Wallhaven;\n\n$wh = new Wallhaven();\n```\n\nIf you have an account on Wallhaven, you can use it to login and access all available wallpapers:\n```php\n$wh = new Wallhaven('YOUR_USERNAME', 'YOUR_PASSWORD');\n```\n\n### Searching\nYou can search for wallpapers and filter them using the `Wallhaven::filter()` method. It returns a `Filter` object that acts as a fluent interface with the following methods:\n\n - `keywords()` – Search query or #tagname, for example:\n\t -  `\"landscape\"`\n\t -  `\"#cars\"`\n - `categories()` – Category, or multiple categories as a bit field. For example:\n\t - `Category::PEOPLE` \n\t - `Category::GENERAL | Category::PEOPLE`\n\t - `Category::ALL` (default) - shorthand for `Category::GENERAL | Category::ANIME | Category::PEOPLE`\n - `purity()` – Purity, or multiple purities as a bit field. For example:\n\t - `Purity::SFW` (default)\n\t - `Purity::SFW | Purity::SKETCHY`\n\t - `Purity::ALL` - shorthand for `Purity::SFW | Purity::SKETCHY | Purity::NSFW`\n - `sorting()` – Sorting. Can be one of the following:\n\t - `Sorting::RELEVANCE` (default)\n\t - `Sorting::RANDOM`\n\t - `Sorting::DATE_ADDED`\n\t - `Sorting::VIEWS`\n\t - `Sorting::FAVORITES`\n - `order()` – Order of results. Can be one of the following:\n\t - `Order::DESC` (default)\n\t - `Order::ASC`\n - `resolutions()` – Resolutions. Should be an array of strings in the format of WxH, for example:\n\t - `[\"1920x1080\"]`\n\t - `[\"1280x720\", \"2560x1440\"]`\n - `ratios()` – Ratios. Should be an array of strings in the format of WxH, for example:\n\t - `[\"9x16\"]`\n\t - `[\"16x9\", \"4x3\"]`\n - `pages()`– Number of pages to fetch from Wallhaven. A single page typically consists of 24, 32 or 64 wallpapers.\n - `getWallpapers()` – Execute the search with the specified filters.\n\nExamples:\n```php\n$wallpapers = $wh-\u003efilter()\n\t-\u003ekeywords(\"#cars\")\n\t-\u003ecategories(Category::GENERAL)\n\t-\u003epurity(Purity::SFW)\n\t-\u003esorting(Sorting::FAVORITES)\n\t-\u003eorder(Order::DESC)\n\t-\u003eresolutions([\"1920x1080\", \"2560x1440\"])\n\t-\u003eratios([\"16x9\"])\n\t-\u003epages(3)\n\t-\u003egetWallpapers();\n```\n\n```php\n$wallpapers = $wh-\u003efilter()\n\t-\u003ekeywords(\"landscape\")\n\t-\u003eratios([\"16x9\"])\n\t-\u003epages(2)\n\t-\u003egetWallpapers();\n```\nReturns a `WallpaperList` object containing `Wallpaper` objects that match the criteria above.\n\nThe `WallpaperList` object can be accessed like an array, iterated over using `foreach`, and has a `WallpaperList::count()` method:\n```php\n// Get favorites count for the first wallpaper in the list\n$wallpapers[0]-\u003egetFavorites();\n\n// Print resolutions of all wallpapers in the list\nforeach ($wallpapers as $w) {\n\techo $w-\u003egetResolution() . PHP_EOL;\n}\n\n// Get the number of wallpapers in the list\necho \"There are \" . $wallpapers-\u003ecount() . \" wallpapers!\" . PHP_EOL;\n```\n\n### Wallpaper Information\nThe `Wallpaper` object has a number of methods that provide information about the wallpaper:\n\n- `getId()`\n- `getTags()`\n- `getPurity()`\n- `getResolution()`\n- `getSize()`\n- `getCategory()`\n- `getViews()`\n- `getFavorites()`\n- `getFeaturedBy()` - not accessible if not logged in\n- `getFeaturedDate()` - not accessible if not logged in\n- `getUploadedBy()`\n- `getUploadedDate()`\n- `getImageUrl()`\n- `getThumbnailUrl()`\n\nYou can get information about a single wallpaper if you know its ID:\n```php\n$w = $wh-\u003ewallpaper(198320);\n\n$w-\u003egetTags();  // [\"cats\", \"closeups\"]\n$w-\u003egetViews(); // int(3500)\n```\n\nYou can also get information about wallpapers from a search result:\n```php\n$wallpapers = $wh-\u003efilter()-\u003ekeywords(...)-\u003egetWallpapers();\n\n$wallpapers[0]-\u003egetId();        // int(103929)\n$wallpapers[0]-\u003egetFavorites(); // int(367)\n```\n\n### Downloading\nTo download a single wallpaper to a specific directory:\n```php\n$wh-\u003ewallpaper(198320)-\u003edownload(\"/home/user/wallpapers\");\n```\n\nTo batch download wallpapers from a search result:\n```php\n$wallpapers = $wh-\u003efilter()-\u003ekeywords(...)-\u003egetWallpapers();\n$wallpapers-\u003edownloadAll(\"/home/user/wallpapers\");\n```\n\nYou can also create a `WallpaperList`, add specific wallpapers to it, and then batch download them, like so:\n```php\nuse Wallhaven\\Wallhaven;\nuse Wallhaven\\WallpaperList;\n\n$wh = new Wallhaven();\n$batch = new WallpaperList();\n$batch[] = $wh-\u003ewallpaper(198320);\n$batch[] = $wh-\u003ewallpaper(103929);\n\n$batch-\u003edownloadAll(\"/home/user/wallpapers\");\n```\n\n\n#### For more information, please refer to the source code and the PHPDoc blocks.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivkos%2Fwallhaven4php","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivkos%2Fwallhaven4php","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivkos%2Fwallhaven4php/lists"}