OpacityImageEffect.php in Imagick 8
File
src/Plugin/ImageEffect/OpacityImageEffect.php
View source
<?php
namespace Drupal\imagick\Plugin\ImageEffect;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Image\ImageInterface;
use Drupal\image\ConfigurableImageEffectBase;
class OpacityImageEffect extends ConfigurableImageEffectBase {
public function applyEffect(ImageInterface $image) {
if (!$image
->apply('opacity', $this->configuration)) {
$this->logger
->error('Image coloroverlay failed using the %toolkit toolkit on %path (%mimetype)', [
'%toolkit' => $image
->getToolkitId(),
'%path' => $image
->getSource(),
'%mimetype' => $image
->getMimeType(),
]);
return FALSE;
}
return TRUE;
}
public function getSummary() {
$summary = parent::getSummary();
$summary['#markup'] = '- ' . $this->configuration['alpha'] . '%';
return $summary;
}
public function defaultConfiguration() {
return [
'alpha' => 50,
];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = [
'#type' => 'container',
'#attributes' => [
'class' => [
'colorform',
],
],
];
$form['alpha'] = [
'#type' => 'number',
'#title' => $this
->t('Opacity'),
'#description' => $this
->t('Opacity of the color overlay in percents.'),
'#default_value' => $this->configuration['alpha'],
'#min' => 0,
'#max' => 100,
];
return $form;
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['alpha'] = $form_state
->getValue('alpha');
}
}