Skip to content

Commit

Permalink
ENH Allow devs to define support for third-party intervention drivers
Browse files Browse the repository at this point in the history
  • Loading branch information
GuySartorelli committed Jun 4, 2024
1 parent 159e152 commit f402de8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/Conversion/InterventionImageFileConverter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -16,6 +17,8 @@
*/
class InterventionImageFileConverter implements FileConverter
{
use Extensible;

public function supportsConversion(string $fromExtension, string $toExtension, array $options = []): bool
{
$unsupportedOptions = $this->validateOptions($options);
Expand Down Expand Up @@ -90,16 +93,19 @@ 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;
}

// 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, $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,
Expand Down

0 comments on commit f402de8

Please sign in to comment.