-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Filters with dynamic options | ||
|
||
When we need a lot of variants of filter, we have to create filters individually. With options, we just define one. | ||
|
||
Replace filter resolver from default (can't options) to one of: | ||
|
||
### Contributte\Imagist\Resolver\FilterResolvers\SimpleFilterResolver | ||
Readable but simple format, options must be list of string, int or bool. | ||
|
||
Example of output: | ||
```php | ||
$image->withFilter('resize', [15, 50]); // output: /cache/_resize-15-50/image.jpg | ||
``` | ||
|
||
Usage: | ||
```yaml | ||
services: | ||
imagist.resolvers.filter: Contributte\Imagist\Resolver\FilterResolvers\SimpleFilterResolver | ||
``` | ||
|
||
### Contributte\Imagist\Resolver\FilterResolvers\MD5FilterResolver | ||
Options must array of scalar | ||
|
||
Example of output: | ||
```php | ||
$image->withFilter('resize', [15, 50]); // output: /cache/_resize-4a783f58efd342dee8bcbce90617131b/image.jpg | ||
``` | ||
|
||
Usage: | ||
```yaml | ||
services: | ||
imagist.resolvers.filter: Contributte\Imagist\Resolver\FilterResolvers\MD5FilterResolver | ||
``` | ||
|
||
## Options in operation | ||
|
||
```php | ||
|
||
use Contributte\Imagist\Bridge\Imagine\OperationInterface; | ||
use Contributte\Imagist\Filter\FilterInterface; | ||
use Contributte\Imagist\Scope\Scope; | ||
use Imagine\Image\Box; | ||
use Imagine\Image\ImageInterface; | ||
|
||
class ResizeOperation implements OperationInterface | ||
{ | ||
|
||
public function supports(FilterInterface $filter, Scope $scope): bool | ||
{ | ||
return $filter->getName() === 'resize'; | ||
} | ||
|
||
public function operate(ImageInterface $image, FilterInterface $filter): void | ||
{ | ||
$image->resize(new Box(...$filter->getOptions())); | ||
} | ||
|
||
} | ||
|
||
``` | ||
|
||
## Usage | ||
|
||
PHP: | ||
```php | ||
$image->withFilter('resize', [15, 50]); // output: /cache/_resize-4a783f58efd342dee8bcbce90617131b/image.jpg | ||
``` | ||
|
||
Latte: | ||
```html | ||
{img $image|filter:resize,15,50} | ||
``` |