-
Notifications
You must be signed in to change notification settings - Fork 379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to flip image horizontally/vertically? #918
Comments
You must implement a custom filter as none of the filters provided by default implement a flip method. For example, here is the basic filter implementation you'd need: <?php
namespace AppBundle\Imagine\Filter\Loader;
use Imagine\Image\ImageInterface;
use Liip\ImagineBundle\Exception\InvalidArgumentException;
use Liip\ImagineBundle\Imagine\Filter\Loader\LoaderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\OptionsResolver\Exception\ExceptionInterface;
class FlipFilter implements LoaderInterface
{
/**
* @param ImageInterface $image
* @param array $options
*
* @return ImageInterface
*/
public function load(ImageInterface $image, array $options = array())
{
try {
$options = (new OptionsResolver())
->setDefault('axis', 'x')
->setAllowedValues('axis', ['x', 'y'])
->resolve($options);
} catch (ExceptionInterface $e) {
throw new InvalidArgumentException('The "axis" option must be set to "x" or "y"', null, $e);
}
if ($options['axis'] === 'x') {
$image->flipHorizontally();
} else {
$image->flipVertically();
}
return $image;
}
} Then, register the filter in your # app/config/services.yml
services:
app.filter.flip_filter:
class: AppBundle\Imagine\Filter\Loader\FlipFilter
tags:
- { name: "liip_imagine.filter.loader", loader: flip_filter } Lastly, again, use the value of the "loader" tag to reference the filter in your configuration: # app/config/config.yml
liip_imagine:
filter_sets:
my_cool_filter_set:
filters:
flip_filter: { axis: x } |
@robfrawley thank you! |
FYI: I just submitted a pull request (#920) that adds the |
quick question: how to flip image vertically and/or horizontally?
The text was updated successfully, but these errors were encountered: