jsor / http-client-hints
用于处理 HTTP 客户端提示的实用工具。
v1.0.0
2018-09-05 06:55 UTC
Requires
- php: ^5.6 || ^7.0
Requires (Dev)
- phpunit/phpunit: ^5.7
This package is auto-updated.
Last update: 2024-09-07 00:12:18 UTC
README
用于处理 HTTP 客户端提示 的实用工具。
安装
使用 Composer 安装最新版本。
composer require jsor/http-client-hints
请查看 Packagist 页面 获取所有可用版本。
示例
$resolved = (new Jsor\HttpClientHints\Resolver()) ->withAllowedHeaders([ // Process only Width and DPR headers 'Width', 'DPR', ]) ->withMapping([ // Map Width header to w key 'width' => 'w', // Needed to extract the height from the query params // for recalculation depending on Width if present 'height' => 'h', ]) ->resolve($_SERVER, $_GET) ; if (isset($resolved['dpr'])) { header('Content-DPR: ' . $resolved['dpr']); header('Vary: DPR', false); } if (isset($resolved['w'])) { header('Vary: Width', false); } // Use $resolved to generate thumbnails. // If you use Glide (https://github.com/thephpleague/glide), this could look // something like: $server = League\Glide\ServerFactory::create([ 'source' => 'path/to/source/folder', 'cache' => 'path/to/cache/folder', ]); $server->outputImage($path, array_merge($_GET, $resolved));
许可证
版权 (c) 2016-2018 Jan Sorgalla。在 MIT 许可证 下发布。