Skip to content

Commit

Permalink
add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
MartkCz committed May 20, 2021
1 parent aa8fc01 commit ed5a2d8
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions .docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- [Doctrine](doctrine.md)
- Filters (image manipulation)
- [Imagine filters](imagine.md)
- [Filters with dynamic options](filters-options.md)
- Examples
- [Gumlet + Google Storage](examples/gumlet-googleStorage.md)

72 changes: 72 additions & 0 deletions .docs/filters-options.md
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}
```

0 comments on commit ed5a2d8

Please sign in to comment.