Skip to content
This repository has been archived by the owner on Feb 8, 2019. It is now read-only.

[FEATURE] using cwebp binary directly #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Classes/Service/OptimizeImageService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use TYPO3\CMS\Core\Utility\MathUtility;

class OptimizeImageService {
public $configuration;

/**
* Initialize
Expand Down Expand Up @@ -32,6 +33,9 @@ public function process($file, $extension = NULL) {
$webpfile = str_replace("." . $extension, ".webp", $file);
$quality = MathUtility::forceIntegerInRange($this->configuration['quality'],1,100);
$command = sprintf('convert %s -quality %s -define webp:lossless=true %s', $file, $quality, $webpfile);
if(isset($this->configuration['useCwebp']) && (bool)$this->configuration['useCwebp'] === true){
$command = sprintf('%s -q %s %s -o %s', $this->configuration['cwebpPath'], $quality, $file, $webpfile);
}
}

if (isset($command)) {
Expand Down
8 changes: 7 additions & 1 deletion ext_conf_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,10 @@
quality = 65

# cat=basic/debug/1000; type=boolean; label=Enable Debugging. The output goes to backend log module when you are logged in
debug = 0
debug = 0

# cat=basic; type=boolean; label=Use cwebp instead of imagemagick
useCwebp = 0

# cat=basic; type=string; label=path to cwebp Binary
cwebpPath = cwebp