Webp.php in WebP 8
File
src/Plugin/ImageAPIOptimizeProcessor/Webp.php
View source
<?php
namespace Drupal\webp\Plugin\ImageAPIOptimizeProcessor;
use Drupal\Core\Form\FormStateInterface;
use Drupal\imageapi_optimize\ConfigurableImageAPIOptimizeProcessorBase;
class Webp extends ConfigurableImageAPIOptimizeProcessorBase {
public function applyToImage($image_uri) {
$webp = \Drupal::service('webp.webp');
$webp
->createWebpCopy($image_uri, $this->configuration['quality']);
}
public function defaultConfiguration() {
return [
'quality' => 100,
];
}
public function buildConfigurationForm(array $form, FormStateInterface $form_state) {
$form['quality'] = [
'#type' => 'number',
'#title' => $this
->t('Image quality'),
'#description' => $this
->t('Specify the image quality.'),
'#default_value' => $this->configuration['quality'],
'#required' => TRUE,
'#min' => 1,
'#max' => 100,
];
return $form;
}
public function submitConfigurationForm(array &$form, FormStateInterface $form_state) {
parent::submitConfigurationForm($form, $form_state);
$this->configuration['quality'] = $form_state
->getValue('quality');
}
}
Classes
Name |
Description |
Webp |
Saves a WebP copy of an image style derivative. |