ImageAPIOptimizeWebPPipeline.php in ImageAPI Optimize WebP 2.x
File
src/Entity/ImageAPIOptimizeWebPPipeline.php
View source
<?php
namespace Drupal\imageapi_optimize_webp\Entity;
use Drupal\imageapi_optimize\Entity\ImageAPIOptimizePipeline;
use Drupal\Core\File\FileSystemInterface;
class ImageAPIOptimizeWebPPipeline extends ImageAPIOptimizePipeline {
public function applyToImage($image_uri) {
parent::applyToImage($image_uri);
$image = \Drupal::service('image.factory')
->get($image_uri);
if (!$image
->isValid()) {
return FALSE;
}
if (count($this
->getProcessors())) {
$webp_uri = $image_uri . '.webp';
foreach ($this->temporaryFiles as $temp_image_uri) {
$temp_webp_uri = $temp_image_uri . '.webp';
if (file_exists($temp_webp_uri)) {
$temp_image_uri = \Drupal::service('file_system')
->copy($temp_webp_uri, $webp_uri, FileSystemInterface::EXISTS_RENAME);
if ($temp_image_uri) {
$this->temporaryFiles[] = $temp_webp_uri;
break;
}
}
}
}
}
}