您能告诉我如何使用LiipImagineBundle
?
NB:我正在使用Symfony2
感谢,
答案 0 :(得分:3)
这对我有用:
<?php
namespace AppBundle\Imagine\Filter\Loader;
use Imagine\Filter\Advanced\Grayscale;
use Imagine\Image\ImageInterface;
use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface;
/**
* Apply a grayscale effect to image.
*/
class GrayscaleFilterLoader implements LoaderInterface
{
/**
* {@inheritdoc}
*/
public function load(ImageInterface $image, array $options = [])
{
$filter = new Grayscale();
return $filter->apply($image);
}
}
只需定义一个像这样的服务:
services:
liip_imagine.filter.loader.grayscale:
class: AppBundle\Imagine\Filter\Loader\GrayscaleFilterLoader
tags:
- { name: liip_imagine.filter.loader, loader: grayscale}
然后是过滤器:
liip_imagine:
filter_sets:
grayscale:
filters:
grayscale: ~
答案 1 :(得分:0)
LiipImagineBundle中没有内置灰度过滤器,因此您可以通过3个步骤创建自定义过滤器加载器:
1)首先,你应该创建GrayscaleFilterLoader类,它应该像任何其他自定义过滤器一样实现Liip \ ImagineBundle \ Imagine \ Filter \ Loader \ LoaderInterface:
namespace AppBundle\Imagine\Filter\Loader;
...
/**
* Class GrayscaleFilterLoader
* @package AppBundle\Imagine\Filter\Loader
*/
class GrayscaleFilterLoader implements LoaderInterface
{
/**
* @param ImageInterface $image
* @param array $options
* @return ImageInterface
*/
public function load(ImageInterface $image, array $options = [])
{
$image->effects()->grayscale();
return $image;
}
}
2)然后,您应该在服务容器中注册它并向其添加liip_imagine.filter.loader标记,loader标记将是过滤器的名称:
#app/config/services.yml
liip_imagine.filter.loader.grayscale:
class: AppBundle\Imagine\Filter\Loader\GrayscaleFilterLoader
tags:
- { name: liip_imagine.filter.loader, loader: grayscale}
3)最后,用它配置过滤器集:
#app/config/config.yml
your_filter_set_name:
filters:
...
grayscale: {}
那就是它!