Comments

jfrederick created an issue. See original summary.

jfrederick’s picture

Status: Active » Needs review
StatusFileSize
new6.12 KB

And a patch

ericduran’s picture

:thumbsup:

mondrake’s picture

Status: Needs review » Needs work
Issue tags: +Needs tests

Thanks @jfrederick

  1. +++ b/config/schema/image_effects.schema.yml
    @@ -299,6 +299,12 @@ image.effect.image_effects_text_overlay:
    +        maximum_chars_ellipsis:
    +          type: boolean
    +          label: 'Ellipsis'
             maximum_width:
    

    Can we have a 'suffix' text here instead of hardcoding an ellipsis? One may want to add [more], (more), >>>, you-know-what, instead of ...
    Text type so that it can be translated.

  2. +++ b/src/Plugin/ImageEffect/TextOverlayImageEffect.php
    --- a/src/Plugin/ImageToolkit/Operation/TextToWrapperTrait.php
    +++ b/src/Plugin/ImageToolkit/Operation/TextToWrapperTrait.php
    
    +++ b/src/Plugin/ImageToolkit/Operation/TextToWrapperTrait.php
    +++ b/src/Plugin/ImageToolkit/Operation/TextToWrapperTrait.php
    @@ -84,6 +84,12 @@ trait TextToWrapperTrait {
    
    @@ -84,6 +84,12 @@ trait TextToWrapperTrait {
           'layout_overflow_action' => [
             'description' => 'Layout overflow action.',
           ],
    +      'text_maximum_chars' => [
    +        'description' => 'Maximum character count.',
    +      ],
    +      'text_maximum_chars_ellipsis' => [
    +        'description' => 'Display ellipsis if text is shortened.',
    +      ],
           'text_maximum_width' => [
             'description' => 'Maximum width, in pixels.',
           ],
    

    Why cut the text in the toolkit operation code? Manipulating the text can be done at the beginning of the TextOverlayImageEffect::getTextWrapper method, and just input to the operation.

I think this deserves a test, too, like e.g. adding the limit when adding the effect to the image style, a very long input text, and measuring the dimensions of the derivative image without and with the limit.

mondrake’s picture

+++ b/src/Plugin/ImageToolkit/Operation/gd/TextToWrapper.php
@@ -62,6 +62,18 @@ class TextToWrapper extends GDImageToolkitOperationBase {
+    // Limit the maximum number of characters.
+    if ($arguments['text_maximum_chars'] > 0) {
+      if (strlen($arguments['text_string']) > $arguments['text_maximum_chars']) {
+        $shorter_string = substr($arguments['text_string'], 0, $arguments['text_maximum_chars']);
+        if ($arguments['text_maximum_chars_ellipsis'] == TRUE) {
+          $shorter_string = $shorter_string . '...';
+        }
+        $arguments['text_string'] = $shorter_string;
+      }
+
+    }

Also I think we should use Unicode:: strlen and Unicode::substr in place of the standard PHP functions.

mondrake’s picture

Issue tags: +D8Media, +Media Initiative

tagging

cyslee’s picture

StatusFileSize
new5.56 KB

Update patch #2 based on @mondrake's comment on #5.

cyslee’s picture

Status: Needs work » Needs review
mondrake’s picture

Title: Text overlay: support a maximum number of characters displayed » Text overlay: add an hook to alter the overlaid text and use it to enable setting maximum number of characters displayed
StatusFileSize
new8.78 KB

Thanks @cyslee

Since there can be endless needs to manipulate the text before overlaying to the image, I was thinking along the lines of adding an hook by means of which any module can alter it as needed. Here I am doing that, adding to the .module file a default implementation of the hook where token resolution, case conversion and length trimming are dealt with.

EDIT: this also covers points in #4 and #5.

mondrake’s picture

Issue tags: -Needs tests, -Media Initiative
StatusFileSize
new10.44 KB
new4.8 KB

Added tests. Plus, the token replacement is better to stay in the effect rather than the hook.

Status: Needs review » Needs work

The last submitted patch, 10: 2702205-9.patch, failed testing.

mondrake’s picture

StatusFileSize
new614 bytes
new10.47 KB
mondrake’s picture

Status: Needs work » Needs review
mondrake’s picture

StatusFileSize
new2.19 KB
new10.66 KB

Fixed todo and added test for conversion to uppercase.

mondrake’s picture

StatusFileSize
new4.12 KB
new12.24 KB

Added update function to add new parameters to Text Overlay effect, and chnaged the hook implementation signature not to be strict on ImageEffectsTextOverlay but rather allow alternative implementations.

mondrake’s picture

StatusFileSize
new518 bytes
new12.24 KB

Wrong numbering of the update function.

mondrake’s picture

Anyone for review?

mondrake’s picture

StatusFileSize
new4.57 KB
new188.44 KB

Learned in #872206: Add possibility to not upscale for "Scale and crop" effect to move update function to post_update, and added a test for the upgrade path.

Also adding a database dump for the update test - based on Drupal 8.2.0 core standard profile + installed Image Effects 8.x-1.0-alpha2

mondrake’s picture

StatusFileSize
new188.32 KB
new4.45 KB

There was a debug leftover in #18

mondrake’s picture

StatusFileSize
new188.84 KB
new533 bytes

Added an empty update function to clean up caches and allow disovery of hook_image_effects_text_overlay_text_alter implemnetations.

  • mondrake committed 81395be on 8.x-1.x
    Issue #2702205 by mondrake, jfrederick, cyslee: Text overlay: add an...
mondrake’s picture

Committed.

mondrake’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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