|
|
Ok!
|
|
|
Ok!
|
|---|---|---|---|---|
| 273 | function webpImage($source, $quality = 100, $removeOld = false)
{
if(strpos('http', $source) !== false) {
//define scheme
$scheme = CMain::IsHTTPS() ? "https" : "http"; // http
//replace http://server with nothing
$source = str_replace([$scheme . '://'. $_SERVER['HTTP_HOST']], [""], $source);
}
if(strpos('http', $source) === false) {
$source = '/home/bitrix/www' . $source;
}
$dir = pathinfo($source, PATHINFO_DIRNAME);
$name = pathinfo($source, PATHINFO_FILENAME);
$destination = $dir . DIRECTORY_SEPARATOR . $name . '.webp';
$info = getimagesize($source);
$isAlpha = false;
echo $info['mime'];
if ($info['mime'] == 'image/jpeg'){
$image = imagecreatefromjpeg($source);
echo $source;
var_dump($image);
} elseif ($isAlpha = $info['mime'] == 'image/gif') {
$image = imagecreatefromgif($source);
} elseif ($isAlpha = $info['mime'] == 'image/png') {
$image = imagecreatefrompng($source);
} else {
return $source;
}
if ($isAlpha) {
imagepalettetotruecolor($image);
imagealphablending($image, true);
imagesavealpha($image, true);
}
imagewebp($image, $destination, $quality);
imagedestroy($image);
if ($removeOld)
unlink($source);
return $destination;
} | webp, convert image, bitrix | 10900 | Функция для Битрикс конвертации картинок в webp |