ivkos/wallhaven
Composer 安装命令:
composer require ivkos/wallhaven
包简介
Wallhaven API - Search, filter and download wallpapers
README 文档
README
Description
A PHP library for Wallhaven 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:
{
"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 require 'vendor/autoload.php';
Initialize Wallhaven:
use Wallhaven\Category; use Wallhaven\Order; use Wallhaven\Purity; use Wallhaven\Sorting; use Wallhaven\Wallhaven; $wh = new Wallhaven();
If you have an account on Wallhaven, you can use it to login and access all available wallpapers:
$wh = new Wallhaven('YOUR_USERNAME', 'YOUR_PASSWORD');
Searching
You 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:
keywords()– Search query or #tagname, for example:"landscape""#cars"
categories()– Category, or multiple categories as a bit field. For example:Category::PEOPLECategory::GENERAL | Category::PEOPLECategory::ALL(default) - shorthand forCategory::GENERAL | Category::ANIME | Category::PEOPLE
purity()– Purity, or multiple purities as a bit field. For example:Purity::SFW(default)Purity::SFW | Purity::SKETCHYPurity::ALL- shorthand forPurity::SFW | Purity::SKETCHY | Purity::NSFW
sorting()– Sorting. Can be one of the following:Sorting::RELEVANCE(default)Sorting::RANDOMSorting::DATE_ADDEDSorting::VIEWSSorting::FAVORITES
order()– Order of results. Can be one of the following:Order::DESC(default)Order::ASC
resolutions()– Resolutions. Should be an array of strings in the format of WxH, for example:["1920x1080"]["1280x720", "2560x1440"]
ratios()– Ratios. Should be an array of strings in the format of WxH, for example:["9x16"]["16x9", "4x3"]
pages()– Number of pages to fetch from Wallhaven. A single page typically consists of 24, 32 or 64 wallpapers.getWallpapers()– Execute the search with the specified filters.
Examples:
$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();
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:
// 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 ingetFeaturedDate()- not accessible if not logged ingetUploadedBy()getUploadedDate()getImageUrl()getThumbnailUrl()
You can get information about a single wallpaper if you know its ID:
$w = $wh->wallpaper(198320); $w->getTags(); // ["cats", "closeups"] $w->getViews(); // int(3500)
You can also get information about wallpapers from a search result:
$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:
$wh->wallpaper(198320)->download("/home/user/wallpapers");
To batch download wallpapers from a search result:
$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:
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.
ivkos/wallhaven 适用场景与选型建议
ivkos/wallhaven 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 130 次下载、GitHub Stars 达 36, 最近一次更新时间为 2015 年 05 月 02 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「api」 「library」 「batch」 「download」 「downloader」 「wallhaven」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 ivkos/wallhaven 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 ivkos/wallhaven 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 ivkos/wallhaven 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Fork of Maatwebsite for reasons of incompatibility with php >= 7.4 --- of Supercharged Excel exports in Laravel
Library with classes to help you do batch.
A PSR-7 compatible library for making CRUD API endpoints
Inbox pattern process implementation for your Laravel Applications
Supercharged Excel exports and imports in Laravel
Core library that defines common interfaces used by the rest of the intahwebz..
统计信息
- 总下载量: 130
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 37
- 点击次数: 31
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-05-02