diff --git a/.github/workflows/phpstan.yml b/.github/workflows/phpstan.yml index 67cd3500..527f156e 100644 --- a/.github/workflows/phpstan.yml +++ b/.github/workflows/phpstan.yml @@ -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 diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index bae94ea3..608968e6 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -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() diff --git a/DependencyInjection/LiipImagineExtension.php b/DependencyInjection/LiipImagineExtension.php index 9ef4a1ae..2a471013 100644 --- a/DependencyInjection/LiipImagineExtension.php +++ b/DependencyInjection/LiipImagineExtension.php @@ -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; @@ -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)); diff --git a/Resources/config/imagine_vips.xml b/Resources/config/imagine_vips.xml new file mode 100644 index 00000000..de460af5 --- /dev/null +++ b/Resources/config/imagine_vips.xml @@ -0,0 +1,15 @@ + + + + + + + + + + + + + diff --git a/Resources/doc/configuration.rst b/Resources/doc/configuration.rst index 0b7cab98..a1ac7444 100644 --- a/Resources/doc/configuration.rst +++ b/Resources/doc/configuration.rst @@ -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 ` 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. diff --git a/composer.json b/composer.json index 34328a8a..55dbcad2 100644 --- a/composer.json +++ b/composer.json @@ -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" },