Skip to content

Commit

Permalink
Webp (#26)
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb authored Aug 28, 2020
1 parent f654545 commit f1a66e3
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/Dispatch.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class Dispatch
protected $_acceptableTypes;
protected $_bits = 0;

private const BIT_WEBP = 0b1;
public const BIT_WEBP = 0b1;
/**
* @var ResponseCacheConfig
*/
Expand Down
3 changes: 2 additions & 1 deletion src/ResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Exception;
use Packaged\Dispatch\Component\DispatchableComponent;
use Packaged\Dispatch\Component\FixedClassComponent;
use Packaged\Helpers\BitWise;
use Packaged\Helpers\Path;
use Packaged\Helpers\Strings;
use Packaged\Helpers\ValueAs;
Expand Down Expand Up @@ -322,7 +323,7 @@ protected function _optimisePath($path, $relativeFullPath)
$this->_optimizeWebP = ValueAs::bool(Dispatch::instance()->config()->getItem('optimisation', 'webp', false));
}

if($this->_optimizeWebP
if($this->_optimizeWebP && BitWise::has(($this->_dispatch ?: Dispatch::instance())->getBits(), Dispatch::BIT_WEBP)
&& in_array(substr($path, -4), ['.jpg', 'jpeg', '.png', '.gif', '.bmp', 'tiff', '.svg'])
&& file_exists($path . '.webp'))
{
Expand Down

0 comments on commit f1a66e3

Please sign in to comment.