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 1703ff5
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 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,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', $format, $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,
// excluding checking for strings that were obviously mimetypes
switch (strtolower($format)) {
switch ($format) {
case 'gif':
// always supported
return true;
Expand Down

0 comments on commit 1703ff5

Please sign in to comment.