MirrorImageEffect.php in Imagick 8
File
src/Plugin/ImageEffect/MirrorImageEffect.php
View source
<?php
namespace Drupal\imagick\Plugin\ImageEffect;
use Drupal\Core\Form\FormStateInterface;
use Drupal\Core\Image\ImageInterface;
use Drupal\image\ConfigurableImageEffectBase;
class MirrorImageEffect extends ConfigurableImageEffectBase {
public function applyEffect(ImageInterface $image) {
if (!$image
->apply('mirror', $this->configuration)) {
$this->logger
->error('Image mirror 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 [
'flip' => 0,
'flop' => 0,
];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['flip'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Mirror image verticaly'),
'#default_value' => $this->configuration['flip'],
];
$form['flop'] = [
'#type' => 'checkbox',
'#title' => $this
->t('Mirror image horizontaly'),
'#default_value' => $this->configuration['flop'],
];
return $form;
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['flip'] = $form_state
->getValue('flip');
$this->configuration['flop'] = $form_state
->getValue('flop');
}
}