Skip to content

Commit

Permalink
Add example
Browse files Browse the repository at this point in the history
  • Loading branch information
jsor committed May 9, 2016
1 parent 0725984 commit d506533
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,45 @@ composer require jsor/http-client-hints
Check the [Packagist page](https://packagist.org/packages/jsor/http-client-hints) for all
available versions.

Example
-------

```php
$resolved = (new Jsor\HttpClientHints\Resolver())
->withWhitelist([
// 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));
```

License
-------

Expand Down

0 comments on commit d506533

Please sign in to comment.