This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function tagPicture($img, $className = 'picture'){ | |
$arWebpFile = pathinfo($img); | |
$webpFile = $_SERVER['DOCUMENT_ROOT'] . "{$arWebpFile["dirname"]}/{$arWebpFile["filename"]}.webp"; | |
if (!file_exists($webpFile)) | |
{ | |
exec("cwebp -q 85 {$_SERVER['DOCUMENT_ROOT']}{$img} -o {$webpFile}"); | |
} | |
$webp = "{$arWebpFile["dirname"]}/{$arWebpFile["filename"]}.webp"; | |
if ($arWebpFile['extension'] == 'png'){ | |
$extension = 'png'; | |
}else{ | |
$extension = 'jpg'; | |
} | |
$picture = "<picture> | |
<source srcset='{$webp}' type=\"image/webp\"> | |
<source srcset=\"{$img}\" type=\"image/{$extension}\"> | |
<img class=\"{$className}\" src=\"{$img}\"> | |
</picture>"; | |
return $picture; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
yum install libwebp-tools
кормим функции png или jpg, получаем webp в теге picture