Skip to content

Commit

Permalink
2.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
AndiLeni committed Jul 28, 2023
1 parent 5569638 commit eb88fc0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 17 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
31 changes: 16 additions & 15 deletions lib/rex_effect_negotiator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion package.yml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
18 changes: 18 additions & 0 deletions pages/index.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<h1>media_negotiator Einstellungen</h1>

<?php

$form = rex_config_form::factory("media_negotiator");


$field = $form->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');

0 comments on commit eb88fc0

Please sign in to comment.