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
265
https://demo.flyimg.io/upload/w_1600,h_1067,c_1,o_jpg/https://modernfotostudio.ru/images/img1-home-top.jpg
afif, url, convert510Конвертер в афиф формал, но сохраняет в жпег формате. Много легче оригинала
241
let dano = $('[name=ORDER_PROP_20]').val(); // 19.03.2023
let dateEn = new Date(dano.substr(6,4), dano.substr(4,2) - 1, dano.substr(0,2), 0, 0, 0).toLocaleDateString('en-CA'); // 2023-03-19
date, JS, convert200Конвертация импортной даты в русскую
223
public function convertImage(&$content)
    {
        if (defined('ADMIN_SECTION') || defined('WIZARD_SITE_ID')) {
            return;
        }

        preg_match_all('/"(/upload/[^"]*.(jpg|jpeg|png))"/i', $content, $matches1);
        self::convertImageToWebp($content, $matches1);
        preg_match_all("/'(/upload/[^']*.(jpg|jpeg|png))'/i", $content, $matches2);
        self::convertImageToWebp($content, $matches2);
    }

    private static function convertImageToWebp(&$content, $matches) {
        if (!empty($matches[1])) {
            foreach ($matches[1] as $i => $imageUrl) {
                $root = $_SERVER['DOCUMENT_ROOT'];
                $type = $matches[2][$i];
                $newName = str_replace($type, 'webp', $imageUrl);
                if (file_exists($root . $newName)) {
                    $content = str_replace($imageUrl, $newName, $content);
                    continue;
                }
                if (!file_exists($root . $imageUrl)) {
                    continue;
                }
                $type = strtolower($type);
                switch ($type) {
                    case 'jpeg':
                    case 'jpg':
                        $img = imagecreatefromjpeg($root . $imageUrl);
                        break;
                    case 'png':
                        $img = imagecreatefrompng($root . $imageUrl);
                        imagepalettetotruecolor($img);
                        imagealphablending($img, true);
                        imagesavealpha($img, true);
                        break;
                }
                if (isset($img)) {
                    $result = imagewebp($img, $root . $newName, 75);
					
					if (!$result) {
						continue;
					}

                    $content = str_replace($imageUrl, $newName, $content);
                    imagedestroy($img);
                    unset($img);
                }
            }
        }
    }
bitrix, webp, convert20030convert image to webp bitrix
55
var d = date_form.replace(/(d+)-(d+)-(d+)/, '$3.$2.$1')
дата, конверт, яваскрипт, дата по-русски, convert, javascript, js, date lat to rus250Яваскрипт преобразование (конверт) даты евро в русскую "2018-08-15" в "15.08.2018"