Skip to content

Commit

Permalink
Merge pull request #42 from gradinarufelix/BUGFIX/vips-support
Browse files Browse the repository at this point in the history
BUGFIX: Fallback to Imagick and to gif instead of webp
  • Loading branch information
mficzel committed Oct 26, 2021
2 parents 7334d75 + 3ec3fd0 commit 6272718
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 8 deletions.
39 changes: 32 additions & 7 deletions Classes/Controller/DummyImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,35 @@ class DummyImageController extends ActionController
*/
protected $logger;

/**
* @Flow\InjectConfiguration
*
* @var array
*/
protected $settings;

/*
* Override the default Imagine driver from Neos.Imagine
* with a static Imagick instance,
* because Vips does not yet support draw
*/
public function initializeObject()
{
if (isset($this->settings['dummyImage']['overrideImagineDriver']) && $this->settings['dummyImage']['overrideImagineDriver'] !== false) {
$className = 'Imagine\\'.$this->settings['dummyImage']['overrideImagineDriver'].'\\Imagine';
$this->imagineService = new $className();
}
}

/**
* Get a dummy-image.
*
* @param int $w
* @param int $h
* @param string $bg
* @param string $fg
* @param string $t
* @param string $f
* @param int $w
* @param int $h
* @param string $bg
* @param string $fg
* @param string|null $t
* @param string $f
*
* @return string
*/
Expand Down Expand Up @@ -110,7 +130,12 @@ public function imageAction(int $w = 600, int $h = 400, string $bg = '#000', str
}

// render image
$result = $image->get($f);
try {
$result = $image->get($f);
} catch (\RuntimeException $e) {
// Render image as png if get() method fails
$result = $image->get($this->settings['dummyImage']['fallbackFormat']);
}
if (!$result) {
throw new \RuntimeException('Something went wrong without throwing an exception');
}
Expand Down
8 changes: 7 additions & 1 deletion Configuration/Settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,10 @@ Neos:
mvc:
routes:
'Sitegeist.Kaleidoscope':
position: 'before Neos.Neos'
position: 'before Neos.Neos'

Sitegeist:
Kaleidoscope:
dummyImage:
fallbackFormat: 'png'
overrideImagineDriver: false
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,27 @@ by our employer http://www.sitegeist.de.*
Sitegeist.Kaleidoscope is available via packagist run `composer require sitegeist/kaleidoscope`.
We use semantic versioning so every breaking change will increase the major-version number.

## Configuration

Some image libraries have problems with WebP image formats. To avoid problems, a fallback image
format can be configured, which will be used for rendering if the requested format fails. The default value is `png`.

```yaml
Sitegeist:
Kaleidoscope:
fallbackFormat: 'png'
```

Moreover, as some image libraries (like Vips) also have problems with the generation of the dummy image, the driver can be overriden.
By default, this value is `false` and the default driver as configured in `Neos.Imagine` is used.
Possible values are `Gd`, `Imagick`, `Gmagick` or `Vips`.

```yaml
Sitegeist:
Kaleidoscope:
overrideImagineDriver: 'Imagick'
```

## Usage

## Image/Picture FusionObjects
Expand Down

0 comments on commit 6272718

Please sign in to comment.