1
0
mirror of https://github.com/processwire/processwire.git synced 2025-08-18 12:31:17 +02:00

added a webp support check for engines

see: https://processwire.com/talk/topic/14236-webp-support/page/3/?tab=comments#comment-185020
This commit is contained in:
horst-n
2019-05-03 13:54:04 +02:00
parent fa917b30e0
commit d361c6c11e
3 changed files with 41 additions and 6 deletions

View File

@@ -57,6 +57,7 @@ class ImageSizerEngineGD extends ImageSizerEngine {
// and if it passes the mandatory requirements, we check particularly aspects here
switch($action) {
case 'imageformat':
// compare current imagefile infos fetched from ImageInspector
$requested = $this->getImageInfo(false);
@@ -69,7 +70,16 @@ class ImageSizerEngineGD extends ImageSizerEngine {
return true;
}
break;
case 'webp':
if(!isset($this->wire('config')->webpSupportGD)) {
// only call it once
$gd = gd_info();
$this->wire('config')->webpSupportGD = isset($gd['WebP Support']) ? $gd['WebP Support'] : false;
}
return $this->wire('config')->webpSupportGD;
break;
case 'install':
/*
$gd = gd_info();
@@ -77,6 +87,7 @@ class ImageSizerEngineGD extends ImageSizerEngine {
$png = isset($gd['PNG Support']) ? $gd['PNG Support'] : false;
$gif = isset($gd['GIF Read Support']) && isset($gd['GIF Create Support']) ? $gd['GIF Create Support'] : false;
$freetype = isset($gd['FreeType Support']) ? $gd['FreeType Support'] : false;
$webp = isset($gd['WebP Support']) ? $gd['WebP Support'] : false;
$this->config->gdReady = true;
*/
return true;

View File

@@ -833,7 +833,13 @@ class Pageimage extends Pagefile {
/** @var ImageSizerEngine $engine */
$engine = $sizer->getEngine();
/* if the current engine installation does not support webp, modify the options param */
if(isset($options['webpAdd']) && $options['webpAdd'] && !$engine->supported('webp')) {
$options['webpAdd'] = false;
$engine->setOptions($options);
}
// allow for ImageSizerEngine module settings for quality and sharpening to override system defaults
// when they are not specified as an option to this resize() method
$engineConfigData = $engine->getConfigData();
@@ -1929,7 +1935,7 @@ class Pageimage extends Pagefile {
$original,
parent::__debugInfo(),
array(
'suffix' => $finalOptions['suffix'],
'suffix' => isset($finalOptions['suffix']) ? $finalOptions['suffix'] : '',
'extension' => $osInfo['extension']
)
));
@@ -1993,7 +1999,8 @@ class Pageimage extends Pagefile {
$enginesArray = array(
'neededEngineSupport' => strtoupper($oSizer->getImageInfo()),
'installedEngines' => $a,
'selectedEngine' => $oSizer->getEngine()->className
'selectedEngine' => $oSizer->getEngine()->className,
'engineWebpSupport' => $oSizer->getEngine()->supported('webp')
);
unset($a, $moduleName, $configData, $engines, $priority, $modules, $oSizer);

View File

@@ -161,7 +161,22 @@ class ImageSizerEngineIMagick extends ImageSizerEngine {
return false;
}
break;
case 'webp':
if(!isset($this->wire('config')->webpSupportIM)) {
// only call it once
ob_start();
phpinfo(INFO_MODULES);
$dump = ob_get_clean();
$list = array();
if(preg_match('#ImageMagick supported formats </td><td.*?>(.*?)</td>#msi', $dump, $matches) && isset($matches[1])) {
$list = explode(',', str_replace(' ', '', mb_strtolower($matches[1])));
}
$this->wire('config')->webpSupportIM = in_array('webp', $list);
}
return $this->wire('config')->webpSupportIM;
break;
case 'install':
return true;
@@ -411,7 +426,9 @@ class ImageSizerEngineIMagick extends ImageSizerEngine {
$this->imWebp->setImageFormat('webp');
$this->imWebp->setImageCompressionQuality($this->webpQuality);
$this->imWebp->setOption('webp:method', '6');
#$this->imWebp->setOption('webp:lossless', 'true');
//$this->imWebp->setOption('webp:lossless', 'true'); // is this useful?
//$this->imWebp->setImageAlphaChannel(imagick::ALPHACHANNEL_ACTIVATE); // is this useful?
//$this->imWebp->setBackgroundColor(new ImagickPixel('transparent')); // is this useful?
// save to file
$return = $this->imWebp->writeImage($webpFilename);
}