SetTransparentColorImageEffect.php in Image Effects 8.3
File
src/Plugin/ImageEffect/SetTransparentColorImageEffect.php
View source
<?php
namespace Drupal\image_effects\Plugin\ImageEffect;
use Drupal\Core\Image\ImageInterface;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Plugin\ContainerFactoryPluginInterface;
use Drupal\image\ConfigurableImageEffectBase;
class SetTransparentColorImageEffect extends ConfigurableImageEffectBase implements ContainerFactoryPluginInterface {
public function defaultConfiguration() {
return [
'transparent_color' => NULL,
] + parent::defaultConfiguration();
}
public function getSummary() {
$data = $this->configuration;
if ($data['transparent_color']) {
$data['color_info'] = [
'#theme' => 'image_effects_color_detail',
'#color' => $data['transparent_color'],
'#border' => TRUE,
'#border_color' => 'matchLuma',
];
}
return [
'#theme' => 'image_effects_set_transparent_color_summary',
'#data' => $data,
] + parent::getSummary();
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['transparent_color'] = [
'#type' => 'image_effects_color',
'#description' => $this
->t('Select a color to be used for transparency of GIF image files. Leave the checkbox ticked to use the color of the image being processed, if it has one.'),
'#allow_null' => TRUE,
'#checkbox_title' => $this
->t('Use source image transparent color'),
'#allow_opacity' => FALSE,
'#default_value' => $this->configuration['transparent_color'],
];
return $form;
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['transparent_color'] = $form_state
->getValue('transparent_color');
}
public function applyEffect(ImageInterface $image) {
return $image
->apply('set_gif_transparent_color', [
'transparent_color' => $this->configuration['transparent_color'],
]);
}
}