| @@ 7-24 (lines=18) @@ | ||
| 4 | ||
| 5 | use Spatie\ImageOptimizer\Image; |
|
| 6 | ||
| 7 | class Pngquant extends BaseOptimizer |
|
| 8 | { |
|
| 9 | public $binaryName = 'pngquant'; |
|
| 10 | ||
| 11 | public function canHandle(Image $image): bool |
|
| 12 | { |
|
| 13 | return $image->mime() === 'image/png'; |
|
| 14 | } |
|
| 15 | ||
| 16 | public function getCommand(): string |
|
| 17 | { |
|
| 18 | $optionString = implode(' ', $this->options); |
|
| 19 | ||
| 20 | return "{$this->binaryName} {$optionString}" |
|
| 21 | .' '.escapeshellarg($this->imagePath) |
|
| 22 | .' --output='.escapeshellarg($this->imagePath); |
|
| 23 | } |
|
| 24 | } |
|
| 25 | ||
| @@ 7-28 (lines=22) @@ | ||
| 4 | ||
| 5 | use Spatie\ImageOptimizer\Image; |
|
| 6 | ||
| 7 | class Svgo extends BaseOptimizer |
|
| 8 | { |
|
| 9 | public $binaryName = 'svgo'; |
|
| 10 | ||
| 11 | public function canHandle(Image $image): bool |
|
| 12 | { |
|
| 13 | if ($image->extension() !== 'svg') { |
|
| 14 | return false; |
|
| 15 | } |
|
| 16 | ||
| 17 | return $image->mime() === 'text/html'; |
|
| 18 | } |
|
| 19 | ||
| 20 | public function getCommand(): string |
|
| 21 | { |
|
| 22 | $optionString = implode(' ', $this->options); |
|
| 23 | ||
| 24 | return "{$this->binaryName} {$optionString}" |
|
| 25 | .' --input='.escapeshellarg($this->imagePath) |
|
| 26 | .' --output='.escapeshellarg($this->imagePath); |
|
| 27 | } |
|
| 28 | } |
|
| 29 | ||
| @@ 7-24 (lines=18) @@ | ||
| 4 | ||
| 5 | use Spatie\ImageOptimizer\Image; |
|
| 6 | ||
| 7 | class Mozjpeg extends BaseOptimizer |
|
| 8 | { |
|
| 9 | public $binaryName = 'mozjpeg'; |
|
| 10 | ||
| 11 | public function canHandle(Image $image): bool |
|
| 12 | { |
|
| 13 | return $image->mime() === 'image/jpeg'; |
|
| 14 | } |
|
| 15 | ||
| 16 | public function getCommand(): string |
|
| 17 | { |
|
| 18 | $optionString = implode(' ', $this->options); |
|
| 19 | ||
| 20 | return "{$this->binaryName} {$optionString}" |
|
| 21 | .' -copy none -outfile '.escapeshellarg($this->imagePath) |
|
| 22 | .' '.escapeshellarg($this->imagePath); |
|
| 23 | } |
|
| 24 | } |
|
| 25 | ||