diff --git a/config/schema/image_effects.schema.yml b/config/schema/image_effects.schema.yml index 55c016b..58f7408 100644 --- a/config/schema/image_effects.schema.yml +++ b/config/schema/image_effects.schema.yml @@ -416,24 +416,27 @@ image.effect.image_effects_watermark: type: mapping label: 'Watermark image effect' mapping: + watermark_image: + type: string + label: 'Watermark image path' + watermark_width: + type: string + label: 'Watermark image horizontal resizing' + watermark_height: + type: string + label: 'Watermark image vertical resizing' placement: type: string - label: 'Position of the watermark' + label: 'Position of the watermark image on the canvas' x_offset: - type: integer - label: 'x offset' + type: string + label: 'X offset of the watermark image vs placement' y_offset: - type: integer - label: 'y offset' + type: string + label: 'Y offset of the watermark image vs placement' opacity: type: integer label: 'opacity' - watermark_image: - type: string - label: 'watermark image path' - watermark_scale: - type: integer - label: 'watermark image scale' image.effect.image_effects_convolution: type: mapping diff --git a/image_effects.post_update.php b/image_effects.post_update.php index 26bd1b9..8005d5d 100644 --- a/image_effects.post_update.php +++ b/image_effects.post_update.php @@ -59,5 +59,28 @@ function image_effects_post_update_text_overlay_strip_tags() { } /** + * Update 'watermark' effects parameters. + */ +function image_effects_post_update_watermark_alpha6() { + foreach (ImageStyle::loadMultiple() as $image_style) { + $edited = FALSE; + foreach ($image_style->getEffects() as $effect) { + if ($effect->getPluginId() === "image_effects_watermark") { + $configuration = $effect->getConfiguration(); + if (!empty($configuration['data']['watermark_scale'])) { + $configuration['data']['watermark_width'] = (string) $configuration['data']['watermark_scale'] . '%'; + } + unset($configuration['data']['watermark_scale']); + $effect->setConfiguration($configuration); + $edited = TRUE; + } + } + if ($edited) { + $image_style->save(); + } + } +} + +/** * @} End of "addtogroup updates-8.x-1.0-alpha". */ diff --git a/src/Plugin/ImageEffect/WatermarkImageEffect.php b/src/Plugin/ImageEffect/WatermarkImageEffect.php index b3f6537..cd30d20 100644 --- a/src/Plugin/ImageEffect/WatermarkImageEffect.php +++ b/src/Plugin/ImageEffect/WatermarkImageEffect.php @@ -2,14 +2,15 @@ namespace Drupal\image_effects\Plugin\ImageEffect; +use Drupal\Core\Image\ImageFactory; use Drupal\Core\Image\ImageInterface; use Drupal\Core\Form\FormStateInterface; use Drupal\Core\Plugin\ContainerFactoryPluginInterface; use Drupal\image\ConfigurableImageEffectBase; +use Drupal\image_effects\Component\ImageUtility; use Drupal\image_effects\Plugin\ImageEffectsPluginBaseInterface; use Psr\Log\LoggerInterface; use Symfony\Component\DependencyInjection\ContainerInterface; -use Drupal\Core\Image\ImageFactory; /** * Class WatermarkImageEffect. @@ -22,6 +23,8 @@ use Drupal\Core\Image\ImageFactory; */ class WatermarkImageEffect extends ConfigurableImageEffectBase implements ContainerFactoryPluginInterface { + use AnchorTrait; + /** * The image factory service. * @@ -77,12 +80,13 @@ class WatermarkImageEffect extends ConfigurableImageEffectBase implements Contai */ public function defaultConfiguration() { return [ + 'watermark_image' => '', + 'watermark_width' => NULL, + 'watermark_height' => NULL, 'placement' => 'center-center', 'x_offset' => 0, 'y_offset' => 0, 'opacity' => 100, - 'watermark_image' => '', - 'watermark_scale' => NULL, ] + parent::defaultConfiguration(); } @@ -96,6 +100,9 @@ class WatermarkImageEffect extends ConfigurableImageEffectBase implements Contai ]; $summary += parent::getSummary(); + // Get the human readable label for placement. + $summary['#data']['placement'] = $this->anchorOptions()[$summary['#data']['placement']]; + return $summary; } @@ -103,38 +110,54 @@ class WatermarkImageEffect extends ConfigurableImageEffectBase implements Contai * {@inheritdoc} */ public function buildConfigurationForm(array $form, FormStateInterface $form_state) { + $options = [ + '#title' => $this->t('Watermark image'), + '#description' => $this->t('Image to use as watermark.'), + '#default_value' => $this->configuration['watermark_image'], + ]; + $form['watermark_image'] = $this->imageSelector->selectionElement($options); + $form['watermark_resize'] = [ + '#type' => 'details', + '#title' => $this->t('Watermark resize'), + '#description' => $this->t('Select dimensions either in pixels or as percentage of the current canvas. Leaving one dimension empty will resize the watermark maintaing its aspect ratio. Leave both dimensions empty to apply the watermark in its original dimensions.'), + '#open' => TRUE, + ]; + $form['watermark_resize']['watermark_width'] = array( + '#type' => 'image_effects_px_perc', + '#title' => $this->t('Watermark width'), + '#default_value' => $this->configuration['watermark_width'], + '#size' => 5, + '#maxlength' => 5, + '#required' => FALSE, + ); + $form['watermark_resize']['watermark_height'] = array( + '#type' => 'image_effects_px_perc', + '#title' => $this->t('Watermark height'), + '#default_value' => $this->configuration['watermark_height'], + '#size' => 5, + '#maxlength' => 5, + '#required' => FALSE, + ); $form['placement'] = [ '#type' => 'radios', '#title' => $this->t('Placement'), - '#options' => [ - 'left-top' => $this->t('Top left'), - 'center-top' => $this->t('Top center'), - 'right-top' => $this->t('Top right'), - 'left-center' => $this->t('Center left'), - 'center-center' => $this->t('Center'), - 'right-center' => $this->t('Center right'), - 'left-bottom' => $this->t('Bottom left'), - 'center-bottom' => $this->t('Bottom center'), - 'right-bottom' => $this->t('Bottom right'), - ], + '#options' => $this->anchorOptions(), '#theme' => 'image_anchor', '#default_value' => $this->configuration['placement'], - '#description' => $this->t('Position of the watermark on the underlying image.'), + '#description' => $this->t('Position of the watermark on the canvas.'), ]; $form['x_offset'] = [ - '#type' => 'number', + '#type' => 'image_effects_px_perc', '#title' => $this->t('Horizontal offset'), - '#field_suffix' => 'px', - '#description' => $this->t('Additional horizontal offset from placement.'), + '#description' => $this->t("Additional horizontal offset from placement. Enter a value, and specify if pixels or percent of the canvas width. '+' or no sign shifts the watermark rightward, '-' sign leftward."), '#default_value' => $this->configuration['x_offset'], '#maxlength' => 4, '#size' => 4, ]; $form['y_offset'] = [ - '#type' => 'number', + '#type' => 'image_effects_px_perc', '#title' => $this->t('Vertical offset'), - '#field_suffix' => 'px', - '#description' => $this->t('Additional vertical offset from placement.'), + '#description' => $this->t("Additional vertical offset from placement. Enter a value, and specify if pixels or percent of the canvas height. '+' or no sign shifts the watermark downward, '-' sign upward."), '#default_value' => $this->configuration['y_offset'], '#maxlength' => 4, '#size' => 4, @@ -143,29 +166,13 @@ class WatermarkImageEffect extends ConfigurableImageEffectBase implements Contai '#type' => 'number', '#title' => $this->t('Opacity'), '#field_suffix' => '%', - '#description' => $this->t('Opacity: 0 - 100'), + '#description' => $this->t('Opacity, in percentage, of the watermark on the canvas. 0% is fully transparent, 100% is fully opaque.'), '#default_value' => $this->configuration['opacity'], '#min' => 0, '#max' => 100, '#maxlength' => 3, '#size' => 3, ]; - $options = [ - '#title' => $this->t('File name'), - '#description' => $this->t('Image to use for watermark effect.'), - '#default_value' => $this->configuration['watermark_image'], - ]; - $form['watermark_image'] = $this->imageSelector->selectionElement($options); - $form['watermark_scale'] = [ - '#type' => 'number', - '#title' => $this->t('Scale'), - '#field_suffix' => '%', - '#description' => $this->t('Scales the overlay image with respect to the source image. Leave empty to use the actual size of the overlay image.'), - '#default_value' => $this->configuration['watermark_scale'], - '#min' => 1, - '#maxlength' => 4, - '#size' => 4, - ]; return $form; } @@ -174,42 +181,59 @@ class WatermarkImageEffect extends ConfigurableImageEffectBase implements Contai */ public function submitConfigurationForm(array &$form, FormStateInterface $form_state) { parent::submitConfigurationForm($form, $form_state); + $this->configuration['watermark_image'] = $form_state->getValue('watermark_image'); + $this->configuration['watermark_width'] = $form_state->getValue(['watermark_resize', 'watermark_width']); + $this->configuration['watermark_height'] = $form_state->getValue(['watermark_resize', 'watermark_height']); $this->configuration['placement'] = $form_state->getValue('placement'); $this->configuration['x_offset'] = $form_state->getValue('x_offset'); $this->configuration['y_offset'] = $form_state->getValue('y_offset'); $this->configuration['opacity'] = $form_state->getValue('opacity'); - $this->configuration['watermark_image'] = $form_state->getValue('watermark_image'); - $this->configuration['watermark_scale'] = $form_state->getValue('watermark_scale'); } /** * {@inheritdoc} */ public function applyEffect(ImageInterface $image) { + // Get the watermark image object. $watermark_image = $this->imageFactory->get($this->configuration['watermark_image']); if (!$watermark_image->isValid()) { $this->logger->error('Image watermark failed using the %toolkit toolkit on %path', ['%toolkit' => $image->getToolkitId(), '%path' => $this->configuration['watermark_image']]); return FALSE; } - if ($this->configuration['watermark_scale'] !== NULL && $this->configuration['watermark_scale'] > 0) { - // Scale the overlay with respect to the dimensions of the source being - // overlaid. To maintain the aspect ratio, only the width of the overlay - // is scaled like that, the height of the overlay follows the aspect - // ratio. - $overlay_w = round($image->getWidth() * $this->configuration['watermark_scale'] / 100); - if (!$watermark_image->scale($overlay_w, NULL, TRUE)) { - return FALSE; + + // Determine watermark dimensions if they need to be changed. + if ((bool) $this->configuration['watermark_width'] || (bool) $this->configuration['watermark_height']) { + $watermark_aspect = $watermark_image->getHeight() / $watermark_image->getWidth(); + $watermark_width = ImageUtility::percentFilter($this->configuration['watermark_width'], $image->getWidth()); + $watermark_height = ImageUtility::percentFilter($this->configuration['watermark_height'], $image->getHeight()); + if ($watermark_width && !$watermark_height) { + $watermark_height = (int) round($watermark_width * $watermark_aspect); + } + elseif (!$watermark_width && $watermark_height) { + $watermark_width = (int) round($watermark_height / $watermark_aspect); } } + else { + $watermark_width = $watermark_image->getWidth(); + $watermark_height = $watermark_image->getHeight(); + } + + // Calculate position of watermark on source image based on placement option. list($x, $y) = explode('-', $this->configuration['placement']); - $x_pos = round(image_filter_keyword($x, $image->getWidth(), $watermark_image->getWidth())); - $y_pos = round(image_filter_keyword($y, $image->getHeight(), $watermark_image->getHeight())); + $x_pos = round(image_filter_keyword($x, $image->getWidth(), $watermark_width)); + $y_pos = round(image_filter_keyword($y, $image->getHeight(), $watermark_height)); + + // Calculate offset based on px/percentage. + $x_offset = ImageUtility::percentFilter($this->configuration['x_offset'], $image->getWidth()); + $y_offset = ImageUtility::percentFilter($this->configuration['y_offset'], $image->getHeight()); return $image->apply('watermark', [ - 'x_offset' => $x_pos + $this->configuration['x_offset'], - 'y_offset' => $y_pos + $this->configuration['y_offset'], - 'opacity' => $this->configuration['opacity'], 'watermark_image' => $watermark_image, + 'watermark_width' => $watermark_width !== $watermark_image->getWidth() ? $watermark_width : NULL, + 'watermark_height' => $watermark_height !== $watermark_image->getHeight() ? $watermark_height : NULL, + 'x_offset' => $x_pos + $x_offset, + 'y_offset' => $y_pos + $y_offset, + 'opacity' => $this->configuration['opacity'], ]); } diff --git a/src/Plugin/ImageToolkit/Operation/WatermarkTrait.php b/src/Plugin/ImageToolkit/Operation/WatermarkTrait.php index d5aca7a..cbf8ac6 100644 --- a/src/Plugin/ImageToolkit/Operation/WatermarkTrait.php +++ b/src/Plugin/ImageToolkit/Operation/WatermarkTrait.php @@ -14,20 +14,34 @@ trait WatermarkTrait { */ protected function arguments() { return [ + 'watermark_image' => [ + 'description' => 'Watermark image.', + ], + 'watermark_width' => [ + 'description' => 'Width of watermark image.', + 'required' => FALSE, + 'default' => NULL, + ], + 'watermark_height' => [ + 'description' => 'Height of watermark image.', + 'required' => FALSE, + 'default' => NULL, + ], 'x_offset' => [ 'description' => 'X offset for watermark image.', + 'required' => FALSE, + 'default' => 0, ], 'y_offset' => [ 'description' => 'Y offset for watermark image.', + 'required' => FALSE, + 'default' => 0, ], 'opacity' => [ 'description' => 'Opacity for watermark image.', 'required' => FALSE, 'default' => 100, ], - 'watermark_image' => [ - 'description' => 'Image to use for watermark effect.', - ], ]; } @@ -48,6 +62,26 @@ trait WatermarkTrait { $source = $arguments['watermark_image']->getSource(); throw new \InvalidArgumentException("Invalid image at {$source}"); } + // Ensure 'watermark_width' is NULL or a positive integer. + $arguments['watermark_width'] = $arguments['watermark_width'] !== NULL ? (int) $arguments['watermark_width'] : NULL; + if ($arguments['watermark_width'] !== NULL && $arguments['watermark_width'] <= 0) { + throw new \InvalidArgumentException("Invalid watermark width ('{$arguments['watermark_width']}') specified for the image 'watermark' operation"); + } + // Ensure 'watermark_height' is NULL or a positive integer. + $arguments['watermark_height'] = $arguments['watermark_height'] !== NULL ? (int) $arguments['watermark_height'] : NULL; + if ($arguments['watermark_height'] !== NULL && $arguments['watermark_height'] <= 0) { + throw new \InvalidArgumentException("Invalid height ('{$arguments['watermark_height']}') specified for the image 'watermark' operation"); + } + // Ensure 'x_offset' is a positive integer. + $arguments['x_offset'] = (int) $arguments['x_offset']; + if ($arguments['x_offset'] < 0) { + throw new \InvalidArgumentException("Invalid X offset ('{$arguments['x_offset']}') specified for the image 'watermark' operation"); + } + // Ensure 'y_offset' is a positive integer. + $arguments['y_offset'] = (int) $arguments['y_offset']; + if ($arguments['y_offset'] < 0) { + throw new \InvalidArgumentException("Invalid Y offset ('{$arguments['y_offset']}') specified for the image 'watermark' operation"); + } return $arguments; } diff --git a/src/Plugin/ImageToolkit/Operation/gd/Watermark.php b/src/Plugin/ImageToolkit/Operation/gd/Watermark.php index 05eb60d..5b6a4e8 100644 --- a/src/Plugin/ImageToolkit/Operation/gd/Watermark.php +++ b/src/Plugin/ImageToolkit/Operation/gd/Watermark.php @@ -25,15 +25,22 @@ class Watermark extends GDImageToolkitOperationBase { * {@inheritdoc} */ protected function execute(array $arguments) { + $watermark = $arguments['watermark_image']; + + // Resize watermark if needed. + if ($arguments['watermark_width'] || $arguments['watermark_height']) { + $watermark->apply('resize', ['width' => $arguments['watermark_width'], 'height' => $arguments['watermark_height']]); + } + return $this->imageCopyMergeAlpha( $this->getToolkit()->getResource(), - $arguments['watermark_image']->getToolkit()->getResource(), + $watermark->getToolkit()->getResource(), $arguments['x_offset'], $arguments['y_offset'], 0, 0, - $arguments['watermark_image']->getToolkit()->getWidth(), - $arguments['watermark_image']->getToolkit()->getHeight(), + $watermark->getToolkit()->getWidth(), + $watermark->getToolkit()->getHeight(), $arguments['opacity'] ); } diff --git a/src/Plugin/ImageToolkit/Operation/imagemagick/Watermark.php b/src/Plugin/ImageToolkit/Operation/imagemagick/Watermark.php index f35fba6..ee7d268 100644 --- a/src/Plugin/ImageToolkit/Operation/imagemagick/Watermark.php +++ b/src/Plugin/ImageToolkit/Operation/imagemagick/Watermark.php @@ -24,7 +24,7 @@ class Watermark extends ImagemagickImageToolkitOperationBase { * {@inheritdoc} */ protected function execute(array $arguments) { - // Overlay image local path. + // Watermark image local path. $local_path = $arguments['watermark_image']->getToolkit()->getSourceLocalPath(); if ($local_path !== '') { $image_path = $this->getToolkit()->escapeShellArg($local_path); @@ -34,11 +34,9 @@ class Watermark extends ImagemagickImageToolkitOperationBase { throw new \InvalidArgumentException("Missing local path for image at {$source_path}"); } - // Set the dimensions of the overlay. Use of the scale option means that we - // need to change the dimensions: always set them, they don't harm when the - // scale option is not used. - $w = $arguments['watermark_image']->getWidth(); - $h = $arguments['watermark_image']->getHeight(); + // Set the dimensions of the overlay. + $w = $arguments['watermark_width'] ?: $arguments['watermark_image']->getToolkit()->getWidth(); + $h = $arguments['watermark_height'] ?: $arguments['watermark_image']->getToolkit()->getHeight(); // Set offset. Offset arguments require a sign in front. $x = $arguments['x_offset'] >= 0 ? ('+' . $arguments['x_offset']) : $arguments['x_offset']; diff --git a/src/Tests/Update/WatermarkUpdateTest.php b/src/Tests/Update/WatermarkUpdateTest.php new file mode 100644 index 0000000..dd8d981 --- /dev/null +++ b/src/Tests/Update/WatermarkUpdateTest.php @@ -0,0 +1,73 @@ +databaseDumpFiles = [ + __DIR__ . '/../../../tests/fixtures/update/d_820_ie_810a2.php.gz', + __DIR__ . '/../../../tests/fixtures/update/test_watermark.php', + ]; + } + + /** + * Tests that 'Watermark' effects are updated properly. + */ + public function testWatermarkUpdate() { + // Test that Watermark effect has parameters as valid before + // 8.x-1.0-alpha6. + $effect_data = $this->config('image.style.test_watermark_scale')->get('effects.3d493386-5251-4d45-b395-2e036f7203c0.data'); + $this->assertFalse(array_key_exists('watermark_width', $effect_data)); + $this->assertFalse(array_key_exists('watermark_height', $effect_data)); + $this->assertIdentical(10, $effect_data['x_offset']); + $this->assertIdentical(10, $effect_data['y_offset']); + $this->assertIdentical(20, $effect_data['watermark_scale']); + + $effect_data = $this->config('image.style.test_watermark_no_scale')->get('effects.253dcaa0-27f0-49ef-9d5f-4bda9bf78ff7.data'); + $this->assertFalse(array_key_exists('watermark_width', $effect_data)); + $this->assertFalse(array_key_exists('watermark_height', $effect_data)); + $this->assertIdentical(10, $effect_data['x_offset']); + $this->assertIdentical(10, $effect_data['y_offset']); + $this->assertNull($effect_data['watermark_scale']); + + // Run updates. + $this->runUpdates(); + + // Test that Watermark effect has parameters as introduced in + // 8.x-1.0-alpha6. + $effect_data = $this->config('image.style.test_watermark_scale')->get('effects.3d493386-5251-4d45-b395-2e036f7203c0.data'); + $this->assertTrue(array_key_exists('watermark_width', $effect_data)); + $this->assertTrue(array_key_exists('watermark_height', $effect_data)); + $this->assertIdentical('10', $effect_data['x_offset']); + $this->assertIdentical('10', $effect_data['y_offset']); + $this->assertIdentical('20%', $effect_data['watermark_width']); + $this->assertFalse(array_key_exists('watermark_scale', $effect_data)); + + $effect_data = $this->config('image.style.test_watermark_no_scale')->get('effects.253dcaa0-27f0-49ef-9d5f-4bda9bf78ff7.data'); + $this->assertTrue(array_key_exists('watermark_width', $effect_data)); + $this->assertTrue(array_key_exists('watermark_height', $effect_data)); + $this->assertIdentical('10', $effect_data['x_offset']); + $this->assertIdentical('10', $effect_data['y_offset']); + $this->assertNull($effect_data['watermark_width']); + $this->assertFalse(array_key_exists('watermark_scale', $effect_data)); + } + +} diff --git a/templates/image-effects-watermark-summary.html.twig b/templates/image-effects-watermark-summary.html.twig index df2c96f..2578ba5 100644 --- a/templates/image-effects-watermark-summary.html.twig +++ b/templates/image-effects-watermark-summary.html.twig @@ -5,12 +5,13 @@ * * Available variables: * - data: The current configuration for this watermark effect, including: + * - watermark_image: The watermark image. + * - watermark_width: The watermark image width. + * - watermark_height: The watermark image height. * - placement: The position of the watermark on the underlying image. * - x_offset: The x_offset of the watermark image. * - y_offset: The y_offset of the watermark image. * - opacity: The opacity of the watermark image. - * - watermark_image: The watermark image. - * - watermark_scale: The watermark image scale. * - effect: The effect information, including: * - id: The effect identifier. * - label: The effect name. @@ -20,10 +21,15 @@ */ #} {% spaceless %} - - {{ 'Image'|t }}: {{ data.watermark_image|e }}, - {% if data.watermark_scale %}{{ 'Scale'|t }}: {{ data.watermark_scale|e }}%,{% endif %} - {{ 'Placement'|t }}: {{ data.placement|e }}, - {% if data.x_offset %}{{ 'X offset'|t }}: {{ data.x_offset|e }}px,{% endif %} - {% if data.y_offset %}{{ 'Y offset'|t }}: {{ data.y_offset|e }}px,{% endif %} - {{ 'Opacity'|t }}: {{ data.opacity|e }}% + - {{ 'Image'|t }}: {{ data.watermark_image|e }} + {% if data.watermark_width or data.watermark_height %} + - {{ 'Watermark width'|t }}: + {% if data.watermark_width %}{{ data.watermark_width|e }}{% else %}{{ '(scaled)'|t }}{% endif %}, + {{ 'height'|t }}: + {% if data.watermark_height %}{{ data.watermark_height|e }}{% else %}{{ '(scaled)'|t }}{% endif %} + {% endif %} + - {{ 'Placement'|t }}: {{ data.placement|e }} + {% if data.x_offset %}- {{ 'X offset'|t }}: {{ data.x_offset|e }}{% endif %} + {% if data.y_offset %}- {{ 'Y offset'|t }}: {{ data.y_offset|e }}{% endif %} + - {{ 'Opacity'|t }}: {{ data.opacity|e }}% {% endspaceless %} diff --git a/tests/fixtures/update/image.style.test_watermark_no_scale.yml b/tests/fixtures/update/image.style.test_watermark_no_scale.yml new file mode 100644 index 0000000..8af8961 --- /dev/null +++ b/tests/fixtures/update/image.style.test_watermark_no_scale.yml @@ -0,0 +1,20 @@ +uuid: 2ab09231-1e24-4f11-809a-6f4e9e8f2793 +langcode: en +status: true +dependencies: + module: + - image_effects +name: test_watermark_no_scale +label: test_watermark_no_scale +effects: + 253dcaa0-27f0-49ef-9d5f-4bda9bf78ff7: + uuid: 253dcaa0-27f0-49ef-9d5f-4bda9bf78ff7 + id: image_effects_watermark + weight: 1 + data: + placement: center-center + x_offset: 10 + y_offset: 10 + opacity: 100 + watermark_image: 'public://image-test.png' + watermark_scale: null diff --git a/tests/fixtures/update/image.style.test_watermark_scale.yml b/tests/fixtures/update/image.style.test_watermark_scale.yml new file mode 100644 index 0000000..64c6c97 --- /dev/null +++ b/tests/fixtures/update/image.style.test_watermark_scale.yml @@ -0,0 +1,20 @@ +uuid: d3f9440c-5ec8-4204-b958-4df8f62b7b03 +langcode: en +status: true +dependencies: + module: + - image_effects +name: test_watermark_scale +label: test_watermark_scale +effects: + 3d493386-5251-4d45-b395-2e036f7203c0: + uuid: 3d493386-5251-4d45-b395-2e036f7203c0 + id: image_effects_watermark + weight: 1 + data: + placement: center-center + x_offset: 10 + y_offset: 10 + opacity: 100 + watermark_image: 'public://image-test.png' + watermark_scale: 20 diff --git a/tests/fixtures/update/test_watermark.php b/tests/fixtures/update/test_watermark.php new file mode 100644 index 0000000..a287788 --- /dev/null +++ b/tests/fixtures/update/test_watermark.php @@ -0,0 +1,21 @@ +insert('config') + ->fields(array( + 'collection' => '', + 'name' => $style, + 'data' => serialize(Yaml::decode(file_get_contents('modules/image_effects/tests/fixtures/update/' . $style . '.yml'))), + )) + ->execute(); +} diff --git a/tests/src/Functional/Effect/WatermarkTest.php b/tests/src/Functional/Effect/WatermarkTest.php index dcfdcb9..274f0c5 100644 --- a/tests/src/Functional/Effect/WatermarkTest.php +++ b/tests/src/Functional/Effect/WatermarkTest.php @@ -42,11 +42,13 @@ class WatermarkTest extends ImageEffectsTestBase { $effect = [ 'id' => 'image_effects_watermark', 'data' => [ + 'watermark_image' => $watermark_uri, 'placement' => 'left-top', - 'x_offset' => 1, - 'y_offset' => 1, + 'x_offset][c0][c1][value' => 1, + 'x_offset][c0][c1][uom' => 'px', + 'y_offset][c0][c1][value' => 1, + 'y_offset][c0][c1][uom' => 'px', 'opacity' => 100, - 'watermark_image' => $watermark_uri, ], ]; $uuid = $this->addEffectToTestStyle($effect); @@ -74,12 +76,13 @@ class WatermarkTest extends ImageEffectsTestBase { $effect = [ 'id' => 'image_effects_watermark', 'data' => [ + 'watermark_image' => $watermark_uri, 'placement' => 'left-top', - 'x_offset' => 0, - 'y_offset' => 0, + 'x_offset][c0][c1][value' => NULL, + 'y_offset][c0][c1][value' => NULL, 'opacity' => 100, - 'watermark_image' => $watermark_uri, - 'watermark_scale' => 5, + 'watermark_resize][watermark_width][c0][c1][value' => 5, + 'watermark_resize][watermark_width][c0][c1][uom' => 'perc', ], ]; $uuid = $this->addEffectToTestStyle($effect); @@ -107,11 +110,11 @@ class WatermarkTest extends ImageEffectsTestBase { $effect = [ 'id' => 'image_effects_watermark', 'data' => [ + 'watermark_image' => $watermark_uri, 'placement' => 'left-top', - 'x_offset' => 0, - 'y_offset' => 0, + 'x_offset][c0][c1][value' => NULL, + 'y_offset][c0][c1][value' => NULL, 'opacity' => 100, - 'watermark_image' => $watermark_uri, ], ]; $uuid = $this->addEffectToTestStyle($effect); @@ -141,11 +144,11 @@ class WatermarkTest extends ImageEffectsTestBase { $effect = [ 'id' => 'image_effects_watermark', 'data' => [ + 'watermark_image' => $watermark_uri, 'placement' => 'left-top', - 'x_offset' => 0, - 'y_offset' => 0, + 'x_offset][c0][c1][value' => NULL, + 'y_offset][c0][c1][value' => NULL, 'opacity' => 50, - 'watermark_image' => $watermark_uri, ], ]; $uuid = $this->addEffectToTestStyle($effect);