Skip to content

Commit

Permalink
Only convert image types
Browse files Browse the repository at this point in the history
  • Loading branch information
bajb committed Jul 5, 2019
1 parent b248678 commit e24dfd9
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/ResourceManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
use function filectime;
use function function_exists;
use function get_class;
use function in_array;
use function ltrim;
use function md5;
use function md5_file;
use function str_replace;
use function strlen;
use function substr;

class ResourceManager
{
Expand Down Expand Up @@ -308,12 +310,11 @@ public function getResourceUri($relativeFullPath, bool $allowComponentBubble = t
protected function _optimisePath($path, $relativeFullPath)
{
$optimise = ValueAs::bool(Dispatch::instance()->config()->getItem('optimisation', 'webp', false));
if($optimise)
if($optimise
&& in_array(substr($path, -4), ['.jpg', 'jpeg', '.png', '.gif', '.bmp', 'tiff', '.svg'])
&& file_exists($path . '.webp'))
{
if(file_exists($path . '.webp'))
{
return [$path . '.webp', $relativeFullPath . '.webp'];
}
return [$path . '.webp', $relativeFullPath . '.webp'];
}
return [$path, $relativeFullPath];
}
Expand Down

0 comments on commit e24dfd9

Please sign in to comment.