From db4854046998b9e9fba4bbeb5a0b1f24d13e6426 Mon Sep 17 00:00:00 2001 From: Guy Sartorelli <36352093+GuySartorelli@users.noreply.github.com> Date: Wed, 5 Jun 2024 10:32:40 +1200 Subject: [PATCH] ENH Allow devs to define support for third-party intervention drivers (#610) --- .../InterventionImageFileConverter.php | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/Conversion/InterventionImageFileConverter.php b/src/Conversion/InterventionImageFileConverter.php index 61b3920d..7c76b22d 100644 --- a/src/Conversion/InterventionImageFileConverter.php +++ b/src/Conversion/InterventionImageFileConverter.php @@ -8,6 +8,7 @@ use SilverStripe\Assets\InterventionBackend; use SilverStripe\Assets\Storage\AssetStore; use SilverStripe\Assets\Storage\DBFile; +use SilverStripe\Core\Extensible; use SilverStripe\Core\Injector\Injector; /** @@ -16,6 +17,8 @@ */ class InterventionImageFileConverter implements FileConverter { + use Extensible; + public function supportsConversion(string $fromExtension, string $toExtension, array $options = []): bool { $unsupportedOptions = $this->validateOptions($options); @@ -90,21 +93,26 @@ private function validateOptions(array $options): array private function supportedByIntervention(string $format, InterventionBackend $backend): bool { $driver = $backend->getImageManager()->config['driver'] ?? null; - // If the driver is somehow not GD or Imagick, we have no way to know what it might support - if ($driver !== 'gd' && $driver !== 'imagick') { - return false; - } // Return early for empty values - we obviously can't support that if ($format === '') { return false; } + $format = strtolower($format); + + // If the driver is somehow not GD or Imagick, we have no way to know what it might support + if ($driver !== 'gd' && $driver !== 'imagick') { + $supported = false; + $this->extend('updateSupportedByIntervention', $supported, $format, $driver); + return $supported; + } + // GD and Imagick support different things. // This follows the logic in intervention's AbstractEncoder::process() method // and the various methods in the Encoder classes for GD and Imagick, // excluding checking for strings that were obviously mimetypes - switch (strtolower($format)) { + switch ($format) { case 'gif': // always supported return true;