Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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;
}
@SeRGei93

This comment has been minimized.

Copy link
Owner Author

SeRGei93 commented Sep 9, 2019

yum install libwebp-tools

кормим функции png или jpg, получаем webp в теге picture

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.