Problem/Motivation

This should be more or less straight port of similar effect from D7 version of ImageCache actions module. Additionally it should be build for ImageMagick, too.

It should allow us to adjust the brightness of an image in the range -100% to +100%.

Proposed resolution

Provide patch and test coverage.

Comments

hctom created an issue. See original summary.

hctom’s picture

StatusFileSize
new9.92 KB

... and here comes the patch ;)

hctom’s picture

Issue summary: View changes
hctom’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 2: add_brightness_image-2651216-2.patch, failed testing.

hctom’s picture

StatusFileSize
new9.92 KB
new1 KB

Fixed errors that occured during automated tests

hctom’s picture

Status: Needs work » Needs review
mondrake’s picture

Status: Needs review » Needs work

Looks pretty good, thank you!

A few minor points below:

+++ b/src/Plugin/ImageEffect/BrightnessImageEffect.php
@@ -0,0 +1,98 @@
+      '@level' => 0,
+    ));
+

I think it should be part of the if...elseif block just below. Not sure "±0%" is very meaningful, though.

+++ b/src/Plugin/ImageEffect/BrightnessImageEffect.php
@@ -0,0 +1,98 @@
+    }
+
+    elseif ($this->configuration['level'] < 0) {

Unnecessary blank line.

+++ b/src/Plugin/ImageToolkit/Operation/gd/Brightness.php
@@ -0,0 +1,50 @@
+  /**
+   * {@inheritdoc}
+   */
+  protected function arguments() {
+    return [
+      'level' => [
+        'description' => 'The brightness level.',
+      ],
+    ];
+  }
+

This is already in the trait, should be removed.

hctom’s picture

Status: Needs work » Needs review
StatusFileSize
new9.75 KB
new1.48 KB

Thanks for the feedback. I changed all your notices and here is the new patch. By the way: I changed "±0%" to "Unchanged" in the effect summary - i guess that makes it better to understand.

mondrake’s picture

Status: Needs review » Needs work
+++ b/src/Plugin/ImageEffect/BrightnessImageEffect.php
@@ -0,0 +1,96 @@
+    if ($this->configuration['level'] > 0) {
+      $level = $this->t('+@level%', array(
+        '@level' => $this->configuration['level'],
+      ));
+    }
+    elseif ($this->configuration['level'] < 0) {
+      $level = $this->t('-@level%', array(
+        '@level' => ltrim($this->configuration['level'], '-'),
+      ));
+    }
+    else {
+      $level = drupal_placeholder($this->t('Unchanged'));
+    }

drupal_placeholder is deprecated so I think we should avoid using it. I think you could use $this->t('%level', ['%level' => $this->t('Unchanged')]); but I did not try it. also you can simplify a bit

    if ($this->configuration['level'] != 0) {
      $level = $this->configuration['level'] > 0 ? $this->t('+@level%', ['@level' => $this->configuration['level']]) : $this->t('@level%', ['@level' $this->configuration['level']]);
    }
    else ...
berdir’s picture

Using t() with just a placeholder is IMHO also bad practice. If anything, then use SafeMarkup::format()/FormattableMarkup.

mondrake’s picture

Alternatively -

a) introduce a twig template to do the formatting
b) just do $level = $this->t('Unchanged'); which is the simplest, you won't be italicizing it but I do not think it's a big deal

hctom’s picture

Yeah, I will give the formatting via a template a try ;)

hctom’s picture

Status: Needs work » Needs review
StatusFileSize
new2.17 KB
new10.72 KB

... and here it comes ;) Summary rendered via a template.

hctom’s picture

StatusFileSize
new10.72 KB
new2.17 KB

Arghhh... forget about the last patch as it did not include my latest code base. Here is a new one

The last submitted patch, 14: add_brightness_image-2651216-14.patch, failed testing.

mondrake’s picture

Status: Needs review » Needs work

Looks great. One last thing before RTBC

+++ b/image_effects.module
@@ -25,6 +25,10 @@ function image_effects_theme() {
+    // Brightness image effect - summary
+    'image_effects_brightness_summary' => [
+      'variables' => ['data' => NULL],
+    ],

I think we should also have the effect in the variables, see the

     'image_effects_watermark_summary' => [
       'variables' => ['data' => NULL, 'effect' => []],
     ...

In fact it looks like the color_shift summary is wrong :(
The core's effects all have an 'effect' key.

hctom’s picture

Status: Needs work » Needs review
StatusFileSize
new10.9 KB
new1016 bytes

Hell yeah, you are right ;) I looked through the watermark implementation and saw this, but I thought it is not necessary, because it is not used in its template. But looking into the core image effects proves this definitely. So now it is added in the variables and documented in the template.

Additionally I will post a little follow up issue for the wrong color shift summary implementation

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Looks OK to me now, RTBC

Additionally I will post a little follow up issue for the wrong color shift summary implementation

Thanks a bunch - in fact I am the culprit here ;)

slashrsm’s picture

Looks good to me too.

  • slashrsm committed 96912b5 on 8.x-1.x authored by hctom
    Issue #2651216 by hctom, mondrake: Add "Brightness" image effect
    
slashrsm’s picture

Status: Reviewed & tested by the community » Fixed

Committed. Thank you!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.