PngCrush.php in Image Optimize Binaries 8
File
src/Plugin/ImageAPIOptimizeProcessor/PngCrush.php
View source
<?php
namespace Drupal\imageapi_optimize_binaries\Plugin\ImageAPIOptimizeProcessor;
use Drupal\Core\File\FileSystemInterface;
use Drupal\imageapi_optimize_binaries\ImageAPIOptimizeProcessorBinaryBase;
class PngCrush extends ImageAPIOptimizeProcessorBinaryBase {
protected function executableName() {
return 'pngcrush';
}
public function applyToImage($image_uri) {
if ($cmd = $this
->getFullPathToBinary()) {
$dst = $this
->sanitizeFilename($image_uri);
if ($this
->getMimeType($image_uri) == 'image/png') {
$temp_file = $this->fileSystem
->tempnam('temporary://', 'file');
$options = array(
'-rem alla',
'-reduce',
'-brute',
'-q',
);
$arguments = array(
$dst,
$this->fileSystem
->realpath($temp_file),
);
if ($this
->execShellCommand($cmd, $options, $arguments)) {
return (bool) \Drupal::service('file_system')
->move($temp_file, $image_uri, FileSystemInterface::EXISTS_REPLACE);
}
}
}
return FALSE;
}
}
Classes
Name |
Description |
PngCrush |
Uses the PngCrush binary to optimize images. |