Warning: Undefined array key "orderhash" in /home/labreunis/maxkuku.ru/docs/webmaster/index.php on line 177
Список полезных функций
(☞ຈل͜ຈ)☞ Главная  Статьи  Загрузчик Домой


Warning: Undefined variable $name in /home/labreunis/maxkuku.ru/docs/webmaster/index.php on line 209

Warning: Undefined array key "orderhash" in /home/labreunis/maxkuku.ru/docs/webmaster/index.php on line 224

Deprecated: strlen(): Passing null to parameter #1 ($string) of type string is deprecated in /home/labreunis/maxkuku.ru/docs/webmaster/index.php on line 224

Warning: Undefined variable $name in /home/labreunis/maxkuku.ru/docs/webmaster/index.php on line 224

Warning: Undefined variable $name in /home/labreunis/maxkuku.ru/docs/webmaster/index.php on line 294
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, bitrix10900Функция для Битрикс конвертации картинок в webp