AddEventHandler("iblock", "OnBeforeIBlockElementAdd", "OnBeforeIBlockElementAddHandler");
function OnAfterIBlockElementAddHandler($arFields)
{
if ($arFields['IBLOCK_ID'] == 42)
{
$size = array("width" => 300, "height" => 300);
if ($arFields[DETAIL_PICTURE] > 0){
CAllFile::ResizeImage($arFields[DETAIL_PICTURE], $size, BX_RESIZE_IMAGE_PROPORTIONAL);
}
$size = array("width" => 120, "height" => 150);
if ($arFields[PREVIEW_PICTURE] > 0){
CAllFile::ResizeImage($arFields[PREVIEW_PICTURE], $size, BX_RESIZE_IMAGE_PROPORTIONAL);
}
$pv = "PROPERTY_VALUES";
$pID = 78; // ID свойства "DOP_FOTO" = 78
$size = array("width" => 300, "height" => 300);
if (count($arFields[$pv][$pID])>0)
{
foreach($arFields[$pv][$pID] as $k => $photo)
{
if (strlen($photo['name'])>0 && !$photo['error'])
{
CAllFile::ResizeImage($arFields[$pv][$pID][$k], $size);
}
}
}
}
}
|