Last active
May 5, 2019 22:24
-
-
Save di7spider/1f4320c5e29681f72737b6508b7e06a2 to your computer and use it in GitHub Desktop.
1C Bitrix (Google PageSpeed) :: CFile::ResizeImageGet + optipng + jpegtran
This file contains hidden or 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
<?php | |
$em = \Bitrix\Main\EventManager::getInstance(); | |
$em->addEventHandler("main", "OnAfterResizeImage", function ($file, $options, &$cacheImageFile, &$cacheImageFileTmp, &$arImageSize){ | |
$path = escapeshellarg($arImageSize); | |
if( !empty($path) ){ | |
try{ | |
if($file['CONTENT_TYPE'] == 'image/png'){ | |
exec('/usr/bin/optipng -o7 -strip all '.$path); | |
}else if($file['CONTENT_TYPE'] == 'image/jpeg'){ | |
exec('/usr/bin/jpegtran -copy none -optimize -outfile '.$path.' '.$path); | |
} | |
}catch (\Exception $e){} | |
} | |
}); | |
?> |
параметра $callbackData не хватает
foreach(GetModuleEvents("main", "OnAfterResizeImage", true) as $arEvent)
{
if(ExecuteModuleEventEx($arEvent, array(
$file,
array($arSize, $resizeType, array(), false, $arFilters),
&$callbackData,
&$cacheImageFile,
&$cacheImageFileTmp,
&$arImageSize,
)))
break;
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Обработчик для Bitrix метода CFile::ResizeImageGet - сжимает итоговое изображение при помощи библиотек optipng и jpegtran
Разместить в /local/php_interface/init.php или /bitrix/php_interface/init.php
На сервере должны быть установлены библиотеки:
http://optipng.sourceforge.net/
http://jpegclub.org/
Дополнительная инфа:
https://developers.google.com/speed/docs/insights/OptimizeImages
http://bxapi.ru/src/?module_id=main&name=CFile::ResizeImageGet
http://dev.1c-bitrix.ru/api_help/main/reference/cfile/resizeimageget.php