View source
<?php
namespace Drupal\imagick\Plugin\ImageEffect;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Image\ImageInterface;
use Drupal\image\ConfigurableImageEffectBase;
class ColorshiftImageEffect extends ConfigurableImageEffectBase {
public function applyEffect(ImageInterface $image) {
if (!$image
->apply('colorshift', $this->configuration)) {
$this->logger
->error('Image colorshift failed using the %toolkit toolkit on %path (%mimetype)', [
'%toolkit' => $image
->getToolkitId(),
'%path' => $image
->getSource(),
'%mimetype' => $image
->getMimeType(),
]);
return FALSE;
}
return TRUE;
}
public function defaultConfiguration() {
return [
'HEX' => '#FF2E2E',
];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form = [
'#type' => 'container',
'#attributes' => [
'class' => [
'colorform',
],
],
];
$form['HEX'] = [
'#type' => 'textfield',
'#title' => $this
->t('HEX'),
'#default_value' => $this->configuration['HEX'],
'#attributes' => [
'class' => [
'colorentry',
],
],
];
$form['colorpicker'] = [
'#weight' => -1,
'#type' => 'container',
'#attributes' => [
'class' => [
'colorpicker',
],
'style' => [
'float:right',
],
],
];
$form['matte_color']['#attached'] = [
'library' => [
'imagick/colorpicker',
],
];
return $form;
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['HEX'] = $form_state
->getValue('HEX');
}
}