InterlaceImageEffect.php in Image Effects 8.3
File
src/Plugin/ImageEffect/InterlaceImageEffect.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 InterlaceImageEffect extends ConfigurableImageEffectBase implements ContainerFactoryPluginInterface {
public function defaultConfiguration() {
return [
'type' => 'Plane',
] + parent::defaultConfiguration();
}
public function getSummary() {
return [
'#theme' => 'image_effects_interlace_summary',
'#data' => $this->configuration,
] + parent::getSummary();
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['type'] = [
'#type' => 'select',
'#title' => $this
->t('Interlace type'),
'#description' => $this
->t('Use <strong>Line</strong> or <strong>Plane</strong> to create an interlaced PNG or GIF or progressive JPEG image. <strong>This setting is not relevant for the GD image toolkit.</strong>'),
'#default_value' => $this->configuration['type'],
'#required' => TRUE,
'#options' => [
'Line' => $this
->t('Line'),
'Plane' => $this
->t('Plane'),
],
];
return $form;
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['type'] = $form_state
->getValue('type');
}
public function applyEffect(ImageInterface $image) {
return $image
->apply('interlace', [
'type' => $this->configuration['type'],
]);
}
}