Мне нужно чтоб превьюшка генерировалась автоматически, привожу полный код
помогите пожайлуста разобраться
Код |
---|
<? function BXIBlockAfterSave($arFields) { $dbr = CIBlockElement::GetByID($arFields['ID']); if(($ar = $dbr->Fetch()) && $ar['DETAIL_PICTURE']>0) { $img_path = $_SERVER['DOCUMENT_ROOT'].CFile::GetPath($ar['DETAIL_PICTURE']); $width = 100; $height = 100; list($width_orig, $height_orig) = getimagesize($img_path); $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($img_path); if ($width_orig>$height_orig) imagecopyresized($image_p, $image, 0, 0, round((max($width_orig,$height_orig)-min($width_orig,$height_orig))/2), 0, $width, $width, min($width_orig,$height_orig), min($width_orig,$height_orig)); if ($width_orig<$height_orig) imagecopyresized($image_p, $image, 0, 0, 0, 0, $width, $width, min($width_orig,$height_orig), min($width_orig,$height_orig)); if ($width_orig==$height_orig) imagecopyresized($image_p, $image, 0, 0, 0, 0, $width, $width, $width_orig, $width_orig); $new_img_path = tempnam("/tmp", "FOO").".jpg"; imagejpeg($image_p, $new_img_path); $be = new CIBlockElement(); $be->Update($arFields['ID'], Array('PREVIEW_PICTURE'=>CFile::MakeFileArray($new_img_path)), false); @unlink($new_img_path); } if($arFields['WF_STATUS_ID']==1) { BXClearCache(true, "/ru/main_page/"); BXClearCache(true, "/ru/detail/".$arFields['ID']."/"); } } ?> |
помогите пожайлуста разобраться
------------------------------------
Все невозможное возможно
Все невозможное возможно