Skip to content

Commit

Permalink
Merge pull request #1496 from liip/PabloKowalczyk-add-vips
Browse files Browse the repository at this point in the history
Pablo kowalczyk add vips
  • Loading branch information
dbu authored Dec 1, 2022
2 parents ee15813 + 5d48d12 commit 76232d0
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/phpstan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@ jobs:
- name: Update project dependencies
uses: ramsey/composer-install@v1

- name: Add vips
run: composer require rokka/imagine-vips

- name: Run PHPStan
run: vendor/bin/phpstan analyze
2 changes: 1 addition & 1 deletion DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ public function getConfigTreeBuilder(): TreeBuilder
->scalarNode('driver')->defaultValue('gd')
->validate()
->ifTrue(function ($v) {
return !\in_array($v, ['gd', 'imagick', 'gmagick'], true);
return !\in_array($v, ['gd', 'imagick', 'gmagick', 'vips'], true);
})
->thenInvalid('Invalid imagine driver specified: %s')
->end()
Expand Down
16 changes: 14 additions & 2 deletions DependencyInjection/LiipImagineExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Liip\ImagineBundle\DependencyInjection;

use Imagine\Vips\Imagine;
use Liip\ImagineBundle\DependencyInjection\Factory\Loader\LoaderFactoryInterface;
use Liip\ImagineBundle\DependencyInjection\Factory\Resolver\ResolverFactoryInterface;
use Liip\ImagineBundle\Imagine\Cache\CacheManager;
Expand Down Expand Up @@ -101,13 +102,24 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('templating.xml');
}

$container->setParameter('liip_imagine.driver_service', 'liip_imagine.'.$config['driver']);
$driver = $config['driver'];
if ('vips' === $driver) {
if (!class_exists(Imagine::class)) {
$vipsImagineClass = Imagine::class;

throw new \RuntimeException("Unable to use 'vips' driver without '{$vipsImagineClass}' class.");
}

$loader->load('imagine_vips.xml');
}

$container->setParameter('liip_imagine.driver_service', "liip_imagine.{$driver}");

$container
->getDefinition('liip_imagine.controller.config')
->replaceArgument(0, $config['controller']['redirect_response_code']);

$container->setAlias('liip_imagine', new Alias('liip_imagine.'.$config['driver']));
$container->setAlias('liip_imagine', new Alias("liip_imagine.{$driver}"));
$container->setAlias(CacheManager::class, new Alias('liip_imagine.cache.manager', false));
$container->setAlias(DataManager::class, new Alias('liip_imagine.data.manager', false));
$container->setAlias(FilterManager::class, new Alias('liip_imagine.filter.manager', false));
Expand Down
15 changes: 15 additions & 0 deletions Resources/config/imagine_vips.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8" ?>
<container xmlns="http://symfony.com/schema/dic/services"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd">

<services>

<service id="liip_imagine.vips" class="Imagine\Vips\Imagine" public="false">
<call method="setMetadataReader">
<argument type="service" id="liip_imagine.meta_data.reader" />
</call>
</service>

</services>
</container>
3 changes: 2 additions & 1 deletion Resources/doc/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ There are several configuration options available:
(which means the standard filesystem loader is used).
* ``post_processors`` - sets post-processors to be applied on filtered image
(see Post-Processors section in the :doc:`filters chapter <filters>` for details).
* ``driver`` - one of the three drivers: ``gd``, ``imagick``, ``gmagick``.
* ``driver`` - one of the drivers: ``gd``, ``imagick``, ``gmagick``, ``vips``.
Default value: ``gd``
* If you want to use vips, you need to additionally require ``rokka/imagine-vips``
* ``default_filter_set_settings`` - specify the default values that will be inherit for any set defined in
``filter_sets``. These values will be overridden if they are specified in the each set. In case of ``filters`` and
``post_processors``, the specified values will be merged with the default ones.
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@
"enqueue/enqueue-bundle": "^0.9 add if you like to process images in background",
"league/flysystem": "required to use FlySystem data loader or cache resolver",
"monolog/monolog": "A psr/log compatible logger is required to enable logging",
"rokka/imagine-vips": "required to use 'vips' driver",
"symfony/messenger": "If you like to process images in background",
"symfony/templating": "required to use deprecated Templating component instead of Twig"
},
Expand Down

0 comments on commit 76232d0

Please sign in to comment.