mirror of
https://github.com/processwire/processwire.git
synced 2025-08-24 07:13:08 +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:
@@ -57,6 +57,7 @@ class ImageSizerEngineGD extends ImageSizerEngine {
|
|||||||
// and if it passes the mandatory requirements, we check particularly aspects here
|
// and if it passes the mandatory requirements, we check particularly aspects here
|
||||||
|
|
||||||
switch($action) {
|
switch($action) {
|
||||||
|
|
||||||
case 'imageformat':
|
case 'imageformat':
|
||||||
// compare current imagefile infos fetched from ImageInspector
|
// compare current imagefile infos fetched from ImageInspector
|
||||||
$requested = $this->getImageInfo(false);
|
$requested = $this->getImageInfo(false);
|
||||||
@@ -70,6 +71,15 @@ class ImageSizerEngineGD extends ImageSizerEngine {
|
|||||||
}
|
}
|
||||||
break;
|
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':
|
case 'install':
|
||||||
/*
|
/*
|
||||||
$gd = gd_info();
|
$gd = gd_info();
|
||||||
@@ -77,6 +87,7 @@ class ImageSizerEngineGD extends ImageSizerEngine {
|
|||||||
$png = isset($gd['PNG Support']) ? $gd['PNG Support'] : false;
|
$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;
|
$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;
|
$freetype = isset($gd['FreeType Support']) ? $gd['FreeType Support'] : false;
|
||||||
|
$webp = isset($gd['WebP Support']) ? $gd['WebP Support'] : false;
|
||||||
$this->config->gdReady = true;
|
$this->config->gdReady = true;
|
||||||
*/
|
*/
|
||||||
return true;
|
return true;
|
||||||
|
@@ -834,6 +834,12 @@ class Pageimage extends Pagefile {
|
|||||||
/** @var ImageSizerEngine $engine */
|
/** @var ImageSizerEngine $engine */
|
||||||
$engine = $sizer->getEngine();
|
$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
|
// 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
|
// when they are not specified as an option to this resize() method
|
||||||
$engineConfigData = $engine->getConfigData();
|
$engineConfigData = $engine->getConfigData();
|
||||||
@@ -1929,7 +1935,7 @@ class Pageimage extends Pagefile {
|
|||||||
$original,
|
$original,
|
||||||
parent::__debugInfo(),
|
parent::__debugInfo(),
|
||||||
array(
|
array(
|
||||||
'suffix' => $finalOptions['suffix'],
|
'suffix' => isset($finalOptions['suffix']) ? $finalOptions['suffix'] : '',
|
||||||
'extension' => $osInfo['extension']
|
'extension' => $osInfo['extension']
|
||||||
)
|
)
|
||||||
));
|
));
|
||||||
@@ -1993,7 +1999,8 @@ class Pageimage extends Pagefile {
|
|||||||
$enginesArray = array(
|
$enginesArray = array(
|
||||||
'neededEngineSupport' => strtoupper($oSizer->getImageInfo()),
|
'neededEngineSupport' => strtoupper($oSizer->getImageInfo()),
|
||||||
'installedEngines' => $a,
|
'installedEngines' => $a,
|
||||||
'selectedEngine' => $oSizer->getEngine()->className
|
'selectedEngine' => $oSizer->getEngine()->className,
|
||||||
|
'engineWebpSupport' => $oSizer->getEngine()->supported('webp')
|
||||||
);
|
);
|
||||||
unset($a, $moduleName, $configData, $engines, $priority, $modules, $oSizer);
|
unset($a, $moduleName, $configData, $engines, $priority, $modules, $oSizer);
|
||||||
|
|
||||||
|
@@ -162,6 +162,21 @@ class ImageSizerEngineIMagick extends ImageSizerEngine {
|
|||||||
}
|
}
|
||||||
break;
|
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':
|
case 'install':
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
@@ -411,7 +426,9 @@ class ImageSizerEngineIMagick extends ImageSizerEngine {
|
|||||||
$this->imWebp->setImageFormat('webp');
|
$this->imWebp->setImageFormat('webp');
|
||||||
$this->imWebp->setImageCompressionQuality($this->webpQuality);
|
$this->imWebp->setImageCompressionQuality($this->webpQuality);
|
||||||
$this->imWebp->setOption('webp:method', '6');
|
$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
|
// save to file
|
||||||
$return = $this->imWebp->writeImage($webpFilename);
|
$return = $this->imWebp->writeImage($webpFilename);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user