OpacityImageEffect.php in Image Effects 8
File
src/Plugin/ImageEffect/OpacityImageEffect.php
View source
<?php
namespace Drupal\image_effects\Plugin\ImageEffect;
use Drupal\Core\Image\ImageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\image\ConfigurableImageEffectBase;
class OpacityImageEffect extends ConfigurableImageEffectBase {
public function defaultConfiguration() {
return [
'opacity' => 50,
] + parent::defaultConfiguration();
}
public function getSummary() {
return [
'#theme' => 'image_effects_opacity_summary',
'#data' => $this->configuration,
] + parent::getSummary();
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['opacity'] = [
'#type' => 'number',
'#title' => $this
->t('Opacity'),
'#field_suffix' => '%',
'#description' => $this
->t('Opacity: 0 - 100'),
'#default_value' => $this->configuration['opacity'],
'#min' => 0,
'#max' => 100,
'#maxlength' => 3,
'#size' => 3,
];
return $form;
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['opacity'] = $form_state
->getValue('opacity');
}
public function applyEffect(ImageInterface $image) {
return $image
->apply('opacity', [
'opacity' => $this->configuration['opacity'],
]);
}
}