From eb88fc048ee32021f7d0fa658f54b7048732d573 Mon Sep 17 00:00:00 2001 From: Andreas Lenhardt Date: Fri, 28 Jul 2023 11:26:42 +0200 Subject: [PATCH] 2.2.0 --- CHANGELOG.md | 5 +++++ lib/Helper.php | 2 +- lib/rex_effect_negotiator.php | 31 ++++++++++++++++--------------- package.yml | 8 +++++++- pages/index.php | 18 ++++++++++++++++++ 5 files changed, 47 insertions(+), 17 deletions(-) create mode 100644 pages/index.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 67beea7..a5f231c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Changelog +## [2.2.0] - 28.07.2023 + +- Added setting to force usage of Imagick. F.e. when GD is not supporting avif as expected. + + ## [2.1.0] - 27.07.2023 diff --git a/lib/Helper.php b/lib/Helper.php index 6384172..f90ee62 100644 --- a/lib/Helper.php +++ b/lib/Helper.php @@ -14,7 +14,7 @@ public static function getOutputFormat($requestedTypes): string { $possibleFormat = ""; - // first check webp and set it, can overridden by avif in next step if avif is available + // first check webp and set it, can be overridden by avif in next step if avif is available if (in_array('image/webp', $requestedTypes)) { // check if webp output is possible diff --git a/lib/rex_effect_negotiator.php b/lib/rex_effect_negotiator.php index 882dce3..aac7e9e 100644 --- a/lib/rex_effect_negotiator.php +++ b/lib/rex_effect_negotiator.php @@ -21,36 +21,37 @@ public function execute() if ($possibleFormat === "avif") { - // check if GD support is available, if yes use GD - if (function_exists('imageavif')) { - // instantiate image formatter class from media manager - $re = new rex_effect_image_format(); - // pass current image to formatter - $re->media = $this->media; - $re->params['convert_to'] = 'avif'; - $re->execute(); - } else { + // check if force_imagick enabled or imageavif not available, else use GD + if (rex_config::get("media_negotiator", "force_imagick", false) || !function_exists('imageavif')) { // use Imagick $img = $this->media->getSource(); $this->media->setImage(Helper::imagickConvert($img, "avif")); $this->media->setFormat("avif"); $this->media->setHeader('Content-Type', "avif"); $this->media->refreshImageDimensions(); - } - } elseif ($possibleFormat === "webp") { - // check if GD support is available, if yes use GD - if (function_exists('imagewebp')) { + } else { + // use GD + // instantiate image formatter class from media manager $re = new rex_effect_image_format(); + // pass current image to formatter $re->media = $this->media; - $re->params['convert_to'] = 'webp'; + $re->params['convert_to'] = 'avif'; $re->execute(); - } else { + } + } elseif ($possibleFormat === "webp") { + + if (rex_config::get("media_negotiator", "force_imagick", false) || !function_exists('imagewebp')) { // use Imagick $img = $this->media->getSource(); $this->media->setImage(Helper::imagickConvert($img, "webp")); $this->media->setFormat("webp"); $this->media->setHeader('Content-Type', "webp"); $this->media->refreshImageDimensions(); + } else { + $re = new rex_effect_image_format(); + $re->media = $this->media; + $re->params['convert_to'] = 'webp'; + $re->execute(); } } else { // do not change format and deliver original file diff --git a/package.yml b/package.yml index 2bcac7c..8009879 100644 --- a/package.yml +++ b/package.yml @@ -1,9 +1,15 @@ package: media_negotiator -version: 2.1.0 +version: 2.2.0 name: Media Negotiator author: Andreas Lenhardt supportpage: https://github.com/AndiLeni/media_negotiator +page: + title: 'Media Negotiator' + +default_config: + force_imagick: false + requires: redaxo: ^5.13.0 php: diff --git a/pages/index.php b/pages/index.php new file mode 100644 index 0000000..a646e1e --- /dev/null +++ b/pages/index.php @@ -0,0 +1,18 @@ +

media_negotiator Einstellungen

+ +addRadioField('force_imagick'); +$field->setLabel("Imagick erzwingen auch wenn GD Funktionen vorhanden"); +$field->addOption('Ja', true); +$field->addOption('Nein', false); + + +$fragment = new rex_fragment(); +$fragment->setVar('class', 'edit', false); +$fragment->setVar('title', "Einstellungen", false); +$fragment->setVar('body', $form->get(), false); +echo $fragment->parse('core/page/section.php');