function GetItems($Params) { global $APPLICATION, $USER; static $checkChildren, $genTmb; if (!isset($checkChildren, $genTmb)) { $checkChildren = COption::GetOptionString("fileman", "file_dialog_check_children", "Y") == 'Y'; $genTmb = COption::GetOptionString("fileman", "file_dialog_gen_thumb", "Y") == 'Y'; } if (strlen($Params["site"]) > 2) { if (!$USER->CanDoOperation('clouds_browse')) { return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_ACCESS_DENIED'), 'access_denied'); } if ($Params['operation'] !== 'O') { return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT') . ' [clouds 04]', 'path_corrupt'); } if (!CModule::IncludeModule('clouds')) { return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT') . ' [clouds 01]', 'path_corrupt'); } $obBucket = null; foreach (CCloudStorageBucket::GetAllBuckets() as $arBucket) { if ($arBucket["ACTIVE"] == "Y" && $arBucket["BUCKET"] === $Params["site"]) { $obBucket = new CCloudStorageBucket($arBucket["ID"]); } } if (!$obBucket) { return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT') . ' [clouds 02]', 'path_corrupt'); } if (!$obBucket->Init()) { return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT') . ' [clouds 03]', 'path_corrupt'); } $path = preg_replace("#[\\\\\\/]+#", "/", "/" . $APPLICATION->UnJSEscape($Params['path'])); $path_js = $path == "" ? "/" : addslashes(htmlspecialcharsex($path)); $path_js = str_replace("//", "/", $path_js); $arFiles = $obBucket->ListFiles($path); if (!is_array($arFiles)) { return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT') . ' [clouds 05]', 'path_corrupt'); } ?> arFDDirs['<?php echo $path_js; ?> '] = []; arFDFiles['<?php echo $path_js; ?> '] = []; <?php foreach ($arFiles["dir"] as $ind => $dir) { ?> arFDDirs['<?php echo $path_js; ?> '][<?php echo $ind; ?> ] = { name : '<?php echo CUtil::JSEscape($dir); ?> ', path : '<?php echo CUtil::JSEscape(preg_replace("#[\\\\\\/]+#", "/", $path . "/" . $dir)); ?> ', empty: false, permission : {del : false, ren : false}, date : '', timestamp : '', size : 0 }; <?php } if ($Params['getFiles']) { foreach ($arFiles['file'] as $ind => $file) { ?> arFDFiles['<?php echo $path_js; ?> '][<?php echo $ind; ?> ] = { name : '<?php echo CUtil::JSEscape($file); ?> ', path : '<?php echo CUtil::JSEscape($obBucket->GetFileSRC($path . "/" . $file)); ?> ', permission : {del : false, ren : false}, date : '', timestamp : '', size : '<?php echo $arFiles["file_size"][$ind]; ?> ' }; <?php } } ?> arFDPermission['<?php echo $path_js; ?> '] = { new_folder : false, upload : false }; <?php return; } $io = CBXVirtualIo::GetInstance(); $site = $Params['site']; $path = $io->CombinePath("/", $APPLICATION->UnJSEscape($Params['path'])); $path_js = $path == "" ? "/" : addslashes(htmlspecialcharsex($path)); $path_js = str_replace("//", "/", $path_js); $bCheckEmpty = $Params['bCheckEmpty']; $rootPath = CSite::GetSiteDocRoot($site); if (!$io->FileExists($rootPath . $path) && !$io->DirectoryExists($rootPath . $path) && $Params['bThrowException'] === true) { return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_PATH_CORRUPT'), 'path_corrupt'); } elseif (!$USER->CanDoFileOperation('fm_view_listing', array($site, $path))) { return $APPLICATION->ThrowException(GetMessage('BX_FD_ERROR') . ': ' . GetMessage('BX_FD_ACCESS_DENIED'), 'access_denied'); } $arDirs = array(); $arFiles = array(); GetDirList(array($site, $path), $arDirs, $arFiles, array(), array("name" => "asc"), "DF", false, true); ?> arFDDirs['<?php echo $path_js; ?> '] = []; arFDFiles['<?php echo $path_js; ?> '] = []; <?php $ind = -1; foreach ($arDirs as $Dir) { $name = addslashes(htmlspecialcharsex($Dir["NAME"])); $path_i = addslashes(htmlspecialcharsex($path)) . "/" . $name; $path_i = str_replace("//", "/", $path_i); $arPath_i = array($site, $path_i); if (!$USER->CanDoFileOperation('fm_view_listing', $arPath_i)) { continue; } $ind++; $empty = true; if ($bCheckEmpty) { $dirTmp = $io->GetDirectory($rootPath . $path . '/' . $name); $arDirTmpChildren = $dirTmp->GetChildren(); foreach ($arDirTmpChildren as $child) { if (!$child->IsDirectory()) { continue; } $empty = false; break; } } $perm_del = $USER->CanDoFileOperation('fm_delete_folder', $arPath_i) ? 'true' : 'false'; $perm_ren = $USER->CanDoFileOperation('fm_rename_folder', $arPath_i) ? 'true' : 'false'; ?> arFDDirs['<?php echo $path_js; ?> '][<?php echo $ind; ?> ] = { name : '<?php echo $name; ?> ', path : '<?php echo $path_i; ?> ', empty: <?php echo $empty ? 'true' : 'false'; ?> , permission : {del : <?php echo $perm_del; ?> , ren : <?php echo $perm_ren; ?> }, date : '<?php echo $Dir["DATE"]; ?> ', timestamp : '<?php echo $Dir["TIMESTAMP"]; ?> ', size : 0 }; <?php } if ($Params['getFiles']) { $ind = -1; foreach ($arFiles as $File) { $name = addslashes(htmlspecialcharsex($File["NAME"])); $path_i = addslashes(htmlspecialcharsex($File["ABS_PATH"])); $path_i = str_replace("//", "/", $path_i); $arPath_i = array($site, $path_i); if (!$USER->CanDoFileOperation('fm_view_file', $arPath_i)) { continue; } $ind++; $perm_del = $USER->CanDoFileOperation('fm_delete_file', $arPath_i) ? 'true' : 'false'; $perm_ren = $USER->CanDoFileOperation('fm_rename_file', $arPath_i) ? 'true' : 'false'; $imageAddProps = ''; if ($genTmb) { $ext = strtolower(GetFileExtension($name)); if (in_array($ext, array('gif', 'jpg', 'jpeg', 'png', 'jpe', 'bmp'))) { $tmbPath = BX_PERSONAL_ROOT . "/tmp/fd_tmb" . $path_i; $destinationFile = $rootPath . $tmbPath; if (!file_exists($destinationFile)) { $sourceFile = $File['PATH']; if (CFile::ResizeImageFile($sourceFile, $destinationFile, array('width' => 140, 'height' => 110))) { $imageAddProps = ",\n" . 'tmb_src : \'' . CUtil::JSEscape($tmbPath) . '\''; } } else { $imageAddProps = ",\n" . 'tmb_src : \'' . CUtil::JSEscape($tmbPath) . '\''; } } } ?> arFDFiles['<?php echo $path_js; ?> '][<?php echo $ind; ?> ] = { name : '<?php echo $name; ?> ', path : '<?php echo $path_i; ?> ', permission : {del : <?php echo $perm_del; ?> , ren : <?php echo $perm_ren; ?> }, date : '<?php echo $File["DATE"]; ?> ', timestamp : '<?php echo $File["TIMESTAMP"]; ?> ', size : '<?php echo $File["SIZE"]; ?> '<?php echo $imageAddProps; ?> }; <?php } } $arPath = array($site, $path); ?> arFDPermission['<?php echo $path_js; ?> '] = { new_folder : <?php echo $USER->CanDoFileOperation('fm_create_new_folder', $arPath) ? 'true' : 'false'; ?> , upload : <?php echo $USER->CanDoFileOperation('fm_upload_file', $arPath) ? 'true' : 'false'; ?> }; <?php }
function ResizePicture($file, $resize, $primaryField, $secondaryField = "") { static $errorFile = array("tmp_name" => "", "del" => "Y"); $external_id = md5($file); if (strlen($file) <= 0) { return $errorFile; } if (file_exists($this->files_dir . $file) && is_file($this->files_dir . $file)) { $file = $this->files_dir . $file; } elseif (file_exists($file) && is_file($file)) { } elseif (($fileId = $this->CheckFileByName($external_id, array($primaryField))) > 0) { return CFile::MakeFileArray($fileId); } elseif ($secondaryField && ($fileId = $this->CheckFileByName($external_id, array($secondaryField))) > 0) { $storedFile = CFile::MakeFileArray($fileId); if ($storedFile) { $tempFile = CTempFile::GetFileName(bx_basename($storedFile["tmp_name"])); CheckDirPath($tempFile); if (copy($storedFile["tmp_name"], $tempFile)) { $storedFile["tmp_name"] = $tempFile; return $storedFile; } else { return $errorFile; } } else { return $errorFile; } } else { return $errorFile; } if (!is_array($resize) || !preg_match("#(\\.)([^./\\\\]+?)\$#", $file)) { $arFile = CFile::MakeFileArray($file, false, false, $external_id); if ($arFile && $this->iblock_resize) { $arFile["COPY_FILE"] = "Y"; } return $arFile; } $i = 1; while (file_exists(preg_replace("#(\\.)([^./\\\\]+?)\$#", ".resize" . $i . ".\\2", $file))) { $i++; } $new_file = preg_replace("#(\\.)([^./\\\\]+?)\$#", ".resize" . $i . ".\\2", $file); if (!CFile::ResizeImageFile($file, $new_file, array("width" => $resize[0], "height" => $resize[1]))) { return CFile::MakeFileArray($file, false, false, $external_id); } $this->arTempFiles[] = $new_file; return CFile::MakeFileArray($new_file, false, false, $external_id); }
function handleFile($hash, $photo, &$package, &$upload, &$error) { if (!CModule::IncludeModule("iblock")) { return false; } global $USER; $arParams = $this->arParams; if (!($upload["SECTION_ID"] > 0)) { if ($this->post["photo_album_id"] > 0) { $upload["SECTION_ID"] = $this->post["photo_album_id"]; } else { $upload["NEW_SECTION_ID"] = $upload["SECTION_ID"] = self::createAlbum($this->arParams, $this->arResult, $this->post["new_album_name"]); } $this->arParams["SECTION_ID"] = $upload["SECTION_ID"]; $upload["redirectUrl"] = CComponentEngine::MakePathFromTemplate($this->arParams["~SECTION_URL"], array("USER_ALIAS" => $this->arParams["USER_ALIAS"], "SECTION_ID" => $this->arParams["SECTION_ID"])); self::adjustIBlock($this->arParams); } if (!($upload["SECTION_ID"] > 0)) { $error = "Album is not created or does not exist."; return false; } $arParams["bxu"]->checkCanvases($hash, $photo, $arParams['converters'], $this->arWatermark); // Props $_REQUEST["Public"] = $_REQUEST["Public"] == "N" ? "N" : "Y"; $Prop = array("REAL_PICTURE" => array("n0" => $photo["files"]["default"]), "PUBLIC_ELEMENT" => array("n0" => $_REQUEST["Public"]), "APPROVE_ELEMENT" => array("n0" => ($arParams["ABS_PERMISSION"] >= "U" || $arParams["APPROVE_BY_DEFAULT"] == "Y") && $_REQUEST["Public"] == "Y" ? "Y" : "X")); foreach ($arParams['converters'] as $val) { if ($val['code'] != "default" && $val['code'] != "thumbnail") { $Prop[strtoupper($val['code'])] = array("n0" => $photo["files"][$val['code']]); } } // Real photo $arFields = array("ACTIVE" => $arParams["MODERATION"] == "Y" && $arParams["ABS_PERMISSION"] < "U" ? "N" : "Y", "MODIFIED_BY" => $USER->GetID(), "IBLOCK_SECTION" => $upload['SECTION_ID'], "IBLOCK_ID" => $arParams["IBLOCK_ID"], "NAME" => $photo['name'], "CODE" => $photo['name'], "TAGS" => $photo['tags'], "DETAIL_TEXT" => $photo['description'], "DETAIL_TEXT_TYPE" => "text", "PREVIEW_PICTURE" => $photo["files"]["thumbnail"], "PREVIEW_TEXT" => $photo['description'], "PREVIEW_TEXT_TYPE" => "text", "PROPERTY_VALUES" => $Prop); $bs = new CIBlockElement(); $ID = $bs->Add($arFields); if ($ID <= 0) { $error = $bs->LAST_ERROR; return false; } $arFields['ID'] = $ID; $_SESSION['arUploadedPhotos'][] = $ID; CIBlockElement::RecalcSections($ID); $arParams['SECTION_ID'] = $upload['SECTION_ID']; $arResult = $this->arResult; foreach (GetModuleEvents("photogallery", "OnAfterUpload", true) as $arEvent) { ExecuteModuleEventEx($arEvent, array(&$arFields, $arParams, $arResult)); } // Add thumbnail only for new album if ($upload["NEW_SECTION_ID"] > 0 && !array_key_exists('NEW_SECTION_PICTURE', $upload)) { $File = $photo["files"]["default"]; // Big picture $File['~tmp_name'] = $File['tmp_name']; $File['tmp_name'] .= "_album_cover.tmp"; if (CFile::ResizeImageFile($File['tmp_name'], $File['tmp_name_1'], array('width' => $arParams["ALBUM_PHOTO_THUMBS"]["SIZE"], 'height' => $arParams["ALBUM_PHOTO_THUMBS"]["SIZE"]), BX_RESIZE_IMAGE_PROPORTIONAL)) { $bs = new CIBlockSection(); if ($bs->Update($upload["SECTION_ID"], array("PICTURE" => $File), false, false)) { $upload['NEW_SECTION_PICTURE'] = true; } } } return $ID; }
/** * @param CCloudStorageBucket $obBucket * @param string $path * @return bool */ public static function ResizeImageFileCheck($obBucket, $path) { global $DB; $path = preg_replace("/^https?:/i", "", $path); $q = $DB->Query("\n\t\t\tselect\n\t\t\t\tID\n\t\t\t\t,ERROR_CODE\n\t\t\t\t,TO_PATH\n\t\t\t\t,FROM_PATH\n\t\t\t\t,PARAMS\n\t\t\t\t," . $DB->DateToCharFunction("TIMESTAMP_X", "FULL") . " TIMESTAMP_X\n\t\t\tfrom b_clouds_file_resize\n\t\t\twhere TO_PATH = '" . $DB->ForSql($path) . "'\n\t\t"); $task = $q->Fetch(); if (!$task) { return false; } if ($task["ERROR_CODE"] !== "0") { if (MakeTimeStamp($task["TIMESTAMP_X"]) + 300 > time() + CTimeZone::GetOffset()) { return false; } } $tmpFile = CFile::MakeFileArray($task["FROM_PATH"]); if (!is_array($tmpFile) || !file_exists($tmpFile["tmp_name"])) { $DB->Query("\n\t\t\t\tUPDATE b_clouds_file_resize\n\t\t\t\tSET ERROR_CODE = '1'\n\t\t\t\tWHERE ID = " . $task["ID"] . "\n\t\t\t"); return false; } $arResizeParams = unserialize($task["PARAMS"]); if (!is_array($arResizeParams)) { $DB->Query("\n\t\t\t\tUPDATE b_clouds_file_resize\n\t\t\t\tSET ERROR_CODE = '2'\n\t\t\t\tWHERE ID = " . $task["ID"] . "\n\t\t\t"); return false; } $arSize = $arResizeParams[0]; $resizeType = $arResizeParams[1]; $arWaterMark = $arResizeParams[2]; $jpgQuality = $arResizeParams[3]; $arFilters = $arResizeParams[4]; $to_path = CFile::GetTempName('', bx_basename($task["TO_PATH"])); if (!CFile::ResizeImageFile($tmpFile["tmp_name"], $to_path, $arSize, $resizeType, $arWaterMark, $jpgQuality, $arFilters)) { $DB->Query("\n\t\t\t\tUPDATE b_clouds_file_resize\n\t\t\t\tSET ERROR_CODE = '3'\n\t\t\t\tWHERE ID = " . $task["ID"] . "\n\t\t\t"); return false; } $fileToStore = CFile::MakeFileArray($to_path); $baseURL = preg_replace("/^https?:/i", "", $obBucket->GetFileSRC("/")); $pathToStore = substr($task["TO_PATH"], strlen($baseURL) - 1); if (!$obBucket->SaveFile(urldecode($pathToStore), $fileToStore)) { $DB->Query("\n\t\t\t\tUPDATE b_clouds_file_resize\n\t\t\t\tSET ERROR_CODE = '4'\n\t\t\t\tWHERE ID = " . $task["ID"] . "\n\t\t\t"); return false; } $DB->Query("\n\t\t\tUPDATE b_clouds_file_resize\n\t\t\tSET ERROR_CODE = '0'\n\t\t\tWHERE ID = " . $task["ID"] . "\n\t\t"); return true; }
if ($object == "user") { $dbUser = CUser::GetByID($USER->GetID()); $arResult["USER"] = $dbUser->GetNext(); $arResult["USER"]["PERSONAL_PHOTO"] = intVal($arResult["USER"]["PERSONAL_PHOTO"]); if ($arResult["USER"]["PERSONAL_PHOTO"] > 0) { $arFile = CFile::MakeFileArray($arResult["USER"]["PERSONAL_PHOTO"]); if (is_array($arFile)) { $arFile["name"] = preg_replace("/[^a-z_.1-9]/is", "_", $arFile["name"]); include_once $_SERVER["DOCUMENT_ROOT"] . "/" . BX_PERSONAL_ROOT . "/components/bitrix/photogallery.upload/functions.php"; $arAlbumSights = array("DETAIL_PICTURE" => array("code" => "album", "notes" => "for_album", "width" => $arParams["PHOTO"]["ALL"]["GALLERY_AVATAR_SIZE"], "height" => $arParams["PHOTO"]["ALL"]["GALLERY_AVATAR_SIZE"]), "PICTURE" => array("code" => "album_thumbs", "notes" => "for_album", "width" => $arParams["PHOTO"]["ALL"]["GALLERY_AVATAR_THUMBS_SIZE"], "height" => $arParams["PHOTO"]["ALL"]["GALLERY_AVATAR_THUMBS_SIZE"])); foreach ($arAlbumSights as $key => $Sight) { $File = $arFile; $File["name"] = "avatar_" . $Sight["code"] . $arFile["name"]; $File["tmp_name"] = CTempFile::GetFileName($File["name"]); CheckDirPath($File["tmp_name"]); $res = CFile::ResizeImageFile(CBXVirtualIo::GetInstance()->GetLogicalName($arFile["tmp_name"]), $File["tmp_name"], $Sight, BX_RESIZE_IMAGE_PROPORTIONAL_ALT); $File["MODULE_ID"] = "iblock"; $arFiles[$key] = $File; } if ($arFile["image"]) { @imagedestroy($arFile["image"]); } } } } $arUserFields = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFields("IBLOCK_" . $arParams["IBLOCK_ID"] . "_SECTION", 0, LANGUAGE_ID); if (empty($arUserFields) || empty($arUserFields["UF_DEFAULT"])) { $db_res = CUserTypeEntity::GetList(array($by => $order), array("ENTITY_ID" => "IBLOK_" . $arParams["IBLOCK_ID"] . "_SECTION", "FIELD_NAME" => "UF_DEFAULT")); if (!$db_res || !($res = $db_res->GetNext())) { $arFields = array("ENTITY_ID" => "IBLOCK_" . $arParams["IBLOCK_ID"] . "_SECTION", "FIELD_NAME" => "UF_DEFAULT", "USER_TYPE_ID" => "string", "MULTIPLE" => "N", "MANDATORY" => "N"); $arFieldName = array();
} $db_res = CIBlockSection::GetList(array(), $arFilter); if ($db_res && ($res = $db_res->Fetch())) { $arError = array("code" => "CODE_EXIST", "title" => GetMessage("P_ERROR_CODE_EXIST")); } } $arFiles = array(); if (empty($arError) && !empty($_FILES["AVATAR"]) && !empty($_FILES["AVATAR"]["tmp_name"])) { include_once $_SERVER["DOCUMENT_ROOT"] . "/" . BX_PERSONAL_ROOT . "/components/bitrix/photogallery.upload/functions.php"; $arRealFile = $_FILES["AVATAR"]; $arAlbumSights = array("DETAIL_PICTURE" => array("code" => "album", "notes" => "for_album", "width" => $arParams["GALLERY_AVATAR"]["WIDTH"], "height" => $arParams["GALLERY_AVATAR"]["HEIGHT"]), "PICTURE" => array("code" => "album_thumbs", "notes" => "for_album", "width" => $arParams["GALLERY_AVATAR_THUMBS"]["WIDTH"], "height" => $arParams["GALLERY_AVATAR_THUMBS"]["HEIGHT"])); foreach ($arAlbumSights as $key => $Sight) { $File = $arRealFile; $File["name"] = "avatar_" . $Sight["code"] . $arRealFile["name"]; $File["tmp_name"] = $File["tmp_name"] = CTempFile::GetFileName() . $File["name"]; CFile::ResizeImageFile($arRealFile["tmp_name"], $File['tmp_name'], $Sight, BX_RESIZE_IMAGE_EXACT); $File["MODULE_ID"] = "iblock"; $arFiles[$key] = $File; } } if (empty($arError)) { $arUserFields = $GLOBALS["USER_FIELD_MANAGER"]->GetUserFields("IBLOCK_" . $arParams["IBLOCK_ID"] . "_SECTION", 0, LANGUAGE_ID); if (empty($arUserFields) || empty($arUserFields["UF_DEFAULT"])) { $db_res = CUserTypeEntity::GetList(array($by => $order), array("ENTITY_ID" => "IBLOCK_" . $arParams["IBLOCK_ID"] . "_SECTION", "FIELD_NAME" => "UF_DEFAULT")); if (!$db_res || !($res = $db_res->GetNext())) { $arFields = array("ENTITY_ID" => "IBLOCK_" . $arParams["IBLOCK_ID"] . "_SECTION", "FIELD_NAME" => "UF_DEFAULT", "USER_TYPE_ID" => "string", "MULTIPLE" => "N", "MANDATORY" => "N"); $arFieldName = array(); $rsLanguage = CLanguage::GetList($by, $order, array()); while ($arLanguage = $rsLanguage->Fetch()) { if (LANGUAGE_ID == $arLanguage["LID"]) { $arFieldName[$arLanguage["LID"]] = GetMessage("IBLOCK_DEFAULT");
function ResizePicture($file, $resize) { if(strlen($file) <= 0) return array("tmp_name"=>"", "del"=>"Y"); if(file_exists($this->files_dir.$file) && is_file($this->files_dir.$file)) $file = $this->files_dir.$file; elseif(file_exists($file) && is_file($file)) ; else return array("tmp_name"=>"", "del"=>"Y"); if(!is_array($resize) || !preg_match("#(\\.)([^./\\\\]+?)$#", $file)) { $arFile = CFile::MakeFileArray($file); if($arFile && $this->iblock_resize) $arFile["COPY_FILE"] = "Y"; return $arFile; } $i = 1; while(file_exists(preg_replace("#(\\.)([^./\\\\]+?)$#", ".resize".$i.".\\2", $file))) $i++; $new_file = preg_replace("#(\\.)([^./\\\\]+?)$#", ".resize".$i.".\\2", $file); if (!CFile::ResizeImageFile($file, $new_file, array("width"=>$resize[0], "height"=>$resize[1]))) return CFile::MakeFileArray($file); $this->arTempFiles[] = $new_file; return CFile::MakeFileArray($new_file); }
/** * При загрузке аватара уменьшаем его размер до 150х150px */ public static function updateAvatar($USER_ID) { $imageMaxWidth = 216; // Максимальная ширина уменьшенной картинки $imageMaxHeight = 216; // Максимальная высота уменьшенной картинки $rsUser = \CUser::GetByID($USER_ID); $arUser = $rsUser->Fetch(); if (intval($arUser["PERSONAL_PHOTO"]) > 0) { $arFile = \CFile::GetFileArray($arUser["PERSONAL_PHOTO"]); // проверяем, что файл является картинкой if (!\CFile::IsImage($arFile["FILE_NAME"])) { echo "не является картинкой"; continue; } // Если размер больше допустимого if ($arFile["WIDTH"] > $imageMaxWidth || $arFile["HEIGHT"] > $imageMaxHeight) { // Временная картинка $tmpFilePath = $_SERVER['DOCUMENT_ROOT'] . "/upload/tmp/" . $arFile["FILE_NAME"]; // Уменьшаем картинку $resizeRez = \CFile::ResizeImageFile($source = $_SERVER['DOCUMENT_ROOT'] . $arFile["SRC"], $dest = $tmpFilePath, array('width' => $imageMaxWidth, 'height' => $imageMaxHeight), $resizeType = BX_RESIZE_IMAGE_EXACT, $waterMark = array(), $jpgQuality = 95); // Записываем изменение в свойство if ($resizeRez && $tmpFilePath) { $arNewFile = \CFile::MakeFileArray($tmpFilePath); $arNewFile['del'] = "Y"; $arNewFile['old_file'] = $arUser['PERSONAL_PHOTO']; $arNewFile["MODULE_ID"] = "main"; $fields['PERSONAL_PHOTO'] = $arNewFile; $user = new \CUser(); $user->Update($arUser["ID"], $fields); $rsUser = \CUser::GetByID($USER_ID); $arUser = $rsUser->Fetch(); // Удалим временный файл unlink($tmpFilePath); } } } return $arUser; }
public static function resizePic($id, $url) { $socialChannel = "vk"; $file_name = $id . ".jpg"; $dir = self::$img_dir; $file_path = $dir . $socialChannel . "_" . $file_name; $file_path_crop = $dir . $socialChannel . "_288x288_" . $file_name; file_put_contents($_SERVER["DOCUMENT_ROOT"] . $file_path, file_get_contents($url)); if (!file_exists($_SERVER["DOCUMENT_ROOT"] . $file_path_crop)) { $resizeRez = CFile::ResizeImageFile($_SERVER["DOCUMENT_ROOT"] . $file_path, $dest = $_SERVER["DOCUMENT_ROOT"] . $file_path_crop, array('width' => 288, 'height' => 288), $resizeType = BX_RESIZE_IMAGE_EXACT, $waterMark = array(), $jpgQuality = 100); } unlink($_SERVER["DOCUMENT_ROOT"] . $file_path); return $file_path_crop; }
function ResizeImageFileCheck($obBucket, $path) { global $DB, $APPLICATION; $path = preg_replace("/^https?:/i", "", $path); $q = $DB->Query(" select ID ,ERROR_CODE ,TO_PATH ,FROM_PATH ,PARAMS ,".$DB->DateToCharFunction("TIMESTAMP_X", "FULL")." TIMESTAMP_X from b_clouds_file_resize where TO_PATH = '".$DB->ForSql($path)."' "); $task = $q->Fetch(); if (!$task) return false; if ($task["ERROR_CODE"] !== "0") { if ((MakeTimeStamp($resize["TIMESTAMP_X"]) + 300/*5min*/) > (time() + CTimeZone::GetOffset())) return false; } $tmpFile = CFile::MakeFileArray($task["FROM_PATH"]); if (!is_array($tmpFile) || !file_exists($tmpFile["tmp_name"])) { $DB->Query(" UPDATE b_clouds_file_resize SET ERROR_CODE = '1' WHERE ID = ".$task["ID"]." "); return false; } $arResizeParams = unserialize($task["PARAMS"]); if (!is_array($arResizeParams)) { $DB->Query(" UPDATE b_clouds_file_resize SET ERROR_CODE = '2' WHERE ID = ".$task["ID"]." "); return false; } $arSize = $arResizeParams[0]; $resizeType = $arResizeParams[1]; $arWaterMark = $arResizeParams[2]; $jpgQuality = $arResizeParams[3]; $arFilters = $arResizeParams[4]; $to_path = CFile::GetTempName('', bx_basename($task["TO_PATH"])); if (!CFile::ResizeImageFile($tmpFile["tmp_name"], $to_path, $arSize, $resizeType, $arWaterMark, $jpgQuality, $arFilters)) { $DB->Query(" UPDATE b_clouds_file_resize SET ERROR_CODE = '3' WHERE ID = ".$task["ID"]." "); return false; } $fileToStore = CFile::MakeFileArray($to_path); $baseURL = preg_replace("/^https?:/i", "", $obBucket->GetFileSRC("/")); $pathToStore = substr($task["TO_PATH"], strlen($baseURL)-1); if (!$obBucket->SaveFile($pathToStore, $fileToStore)) { $DB->Query(" UPDATE b_clouds_file_resize SET ERROR_CODE = '4' WHERE ID = ".$task["ID"]." "); return false; } $DB->Query(" UPDATE b_clouds_file_resize SET ERROR_CODE = '0' WHERE ID = ".$task["ID"]." "); return true; }
if (!file_exists($photoInfo['ORIG']['0']) or 'Y' == $_GET['clear_cache']) { foreach (array('ORIG', 'BIG', 'MED', 'SML') as $photoSize) { @unlink($photoInfo[$photoSize]['0']); } $from = fopen($sourcePhotoPath, 'rb', false); $to = fopen($photoInfo['ORIG']['0'], 'wb', false); $bytes = stream_copy_to_stream($from, $to); if (@file_exists($photoInfo['ORIG']['0']) && 10 > @filesize($photoInfo['ORIG']['0']) or $bytes != @filesize($photoInfo['ORIG']['0'])) { unset($arVehicles[$i]['PHOTO'][$c]); foreach (array('ORIG', 'BIG', 'MED', 'SML') as $photoSize) { @unlink($photoInfo[$photoSize]['0']); } } else { @chmod($photoInfo['ORIG']['0'], 0666); foreach (array('BIG', 'MED', 'SML') as $o => $photoSize) { CFile::ResizeImageFile($photoInfo['ORIG']['0'], $photoInfo[$photoSize]['0'], ${'arSize' . ($o + 1)}, BX_RESIZE_IMAGE_PROPORTIONAL, array(), 80, false); @chmod($photoInfo[$photoSize]['0'], 0666); } } fclose($from); fclose($to); } } } // Марка и модель $arVehicles[$i]['MARK']['ID'] = $vehicle['#']['mark']['0']['@']['mark_id']; $arVehicles[$i]['MARK']['NAME'] = $vehicle['#']['mark']['0']['#']; $arVehicles[$i]['MODEL']['ID'] = $vehicle['#']['model']['0']['@']['model_id']; $arVehicles[$i]['MODEL']['NAME'] = $vehicle['#']['model']['0']['#']; // год выпуска $arVehicles[$i]['YEAR'] = $vehicle['#']['year']['0']['#'];
/** * @param CCloudStorageBucket $obBucket * @param string $path * @return bool */ function ResizeImageFileCheck($obBucket, $path) { global $DB; $path = preg_replace("/^https?:/i", "", $path); $q = $DB->Query(" select ID ,ERROR_CODE ,TO_PATH ,FROM_PATH ,PARAMS ,".$DB->DateToCharFunction("TIMESTAMP_X", "FULL")." TIMESTAMP_X from b_clouds_file_resize where TO_PATH = '".$DB->ForSql($path)."' "); $task = $q->Fetch(); if (!$task) return false; //File in the Sky with Diamonds if ($task["ERROR_CODE"] == 9) { return true; } //Fatal error if ($task["ERROR_CODE"] >= 20) { return false; } //Recoverable error if ($task["ERROR_CODE"] >= 10 && $task["ERROR_CODE"] < 20) { if ((MakeTimeStamp($task["TIMESTAMP_X"]) + 300/*5min*/) > (time() + CTimeZone::GetOffset())) return false; } $DB->Query(" UPDATE b_clouds_file_resize SET ERROR_CODE = '11' WHERE ID = ".$task["ID"]." "); $tmpFile = CFile::MakeFileArray($task["FROM_PATH"]); if (!is_array($tmpFile) || !file_exists($tmpFile["tmp_name"])) { $DB->Query(" UPDATE b_clouds_file_resize SET ERROR_CODE = '22' WHERE ID = ".$task["ID"]." "); return false; } $arResizeParams = unserialize($task["PARAMS"]); if (!is_array($arResizeParams)) { $DB->Query(" UPDATE b_clouds_file_resize SET ERROR_CODE = '23' WHERE ID = ".$task["ID"]." "); return false; } $DB->Query(" UPDATE b_clouds_file_resize SET ERROR_CODE = '14' WHERE ID = ".$task["ID"]." "); $arSize = $arResizeParams[0]; $resizeType = $arResizeParams[1]; $arWaterMark = $arResizeParams[2]; $jpgQuality = $arResizeParams[3]; $arFilters = $arResizeParams[4]; $to_path = CFile::GetTempName('', bx_basename($task["TO_PATH"])); if (!CFile::ResizeImageFile($tmpFile["tmp_name"], $to_path, $arSize, $resizeType, $arWaterMark, $jpgQuality, $arFilters)) { $DB->Query(" UPDATE b_clouds_file_resize SET ERROR_CODE = '25' WHERE ID = ".$task["ID"]." "); return false; } $DB->Query(" UPDATE b_clouds_file_resize SET ERROR_CODE = '16' WHERE ID = ".$task["ID"]." "); $fileToStore = CFile::MakeFileArray($to_path); if ($arResizeParams["type"] && !preg_match("/^image\\//", $fileToStore["type"])) $fileToStore["type"] = $arResizeParams["type"]; $baseURL = preg_replace("/^https?:/i", "", $obBucket->GetFileSRC("/")); $pathToStore = substr($task["TO_PATH"], strlen($baseURL)-1); if (!$obBucket->SaveFile(urldecode($pathToStore), $fileToStore)) { $DB->Query(" UPDATE b_clouds_file_resize SET ERROR_CODE = '27' WHERE ID = ".$task["ID"]." "); return false; } $DB->Query(" UPDATE b_clouds_file_resize SET ERROR_CODE = '9' WHERE ID = ".$task["ID"]." "); return true; }
foreach ($pictures as $title => $options) { if (COption::GetOptionString('imageimport', sprintf('%s_%s', $options['type'], $title), 'N') == 'Y') { $picture_sizes = array('width' => 0, 'height' => 0); switch ($options['sizes']) { case 'iblock': $picture_sizes = array('width' => $iblockFields[$title]['DEFAULT_VALUE']['WIDTH'], 'height' => $iblockFields[$title]['DEFAULT_VALUE']['HEIGHT']); break; case 'option': $picture_sizes = array('width' => $options['width'], 'height' => $options['height']); break; } if (!empty($picture_sizes['width']) or !empty($picture_sizes['height'])) { do { $picture_source = sprintf('%s/_%s_%s_%s', $file_info['dirname'], $title, uniqid(), $file_name); } while (file_exists($picture_source)); CFile::ResizeImageFile($file_path, $picture_source, $picture_sizes); $unlink_queue[] = $picture_source; } else { $picture_source = $file_path; } $picture_array = CFile::MakeFileArray($picture_source); switch ($options['type']) { case 'field': $arFields[$title] = $picture_array; break; case 'property': $arFields['PROPERTY_VALUES'][$options['id']] = $picture_array; break; } } }
protected static function createCanvas($source, $dest, $canvasParams = array(), $watermarkParams = array()) { $watermark = array_key_exists("watermark", $source) ? array() : $watermarkParams; if (\CFile::ResizeImageFile($source["tmp_name"], $dest["tmp_name"], $canvasParams, BX_RESIZE_IMAGE_PROPORTIONAL, $watermark, $canvasParams["quality"], array())) { $dest = array_merge($source, $dest); if (array_key_exists("watermark", $source) || !empty($watermarkParams)) { $dest["watermark"] = true; } } else { $dest["error"] = 348; } return $dest; }
function simpleUploadHandler($arParams, $arResult = array()) { global $APPLICATION; $APPLICATION->RestartBuffer(); $sTmpPath = CImageUploader::SetTmpPath($_REQUEST["PackageGuid"], $arParams["PATH_TO_TMP"]); $savedData = CImageUploader::GetSavedData(); if ($savedData['SECTION_ID']) { unset($savedData['SECTION_ID']); CImageUploader::SetSavedData($savedData); } onBeforeUpload(array('pathToTmp' => $arParams["PATH_TO_TMP"], 'arParams' => $arParams, "~arResult" => $arResult, 'sessid' => bitrix_sessid(), 'packageFields' => array('photo_album_id' => $_POST['photo_album_id'], 'new_album_name' => $_POST['new_album_name'], 'photo_resize_size' => intVal($_POST['photo_resize_size'])))); $files = $_FILES['photos']; $file_count = 0; if (!empty($files)) { if (!is_array($files['name']) && is_string($files['name'])) { $files = array('name' => array($files['name']), 'type' => array($files['type']), 'tmp_name' => array($files['tmp_name']), 'error' => array($files['error']), 'size' => array($files['size'])); } $file_count = count($files['name']); } if ($arParams['WATERMARK_RULES'] == 'ALL') { $arWatermark = array('type' => strtolower($arParams['WATERMARK_TYPE']), 'position' => $arParams['WATERMARK_POSITION']); if ($arParams['WATERMARK_TYPE'] == 'TEXT') { $arWatermark['coefficient'] = $arParams['WATERMARK_SIZE']; $arWatermark['text'] = trim($arParams['WATERMARK_TEXT']); $arWatermark['font'] = trim($arParams['PATH_TO_FONT']); $arWatermark['color'] = trim($arParams['WATERMARK_COLOR']); $arWatermark['use_copyright'] = "N"; } else { $arWatermark['file'] = $arParams['WATERMARK_FILE']; $arWatermark['alpha_level'] = $arParams['WATERMARK_TRANSPARENCY']; $arWatermark['size'] = 'real'; $arWatermark['fill'] = $arParams['WATERMARK_FILE_ORDER'] == 'usual' ? 'exact' : $arParams['WATERMARK_FILE_ORDER']; } } elseif ($_POST['photo_watermark_use'] == 'Y') { $arWatermark = array('type' => $_POST['photo_watermark_type'], 'text' => $_POST['photo_watermark_text'], 'font' => $arParams['PATH_TO_FONT'], 'position' => $_POST['photo_watermark_position'], 'color' => $_POST['photo_watermark_color'], 'size' => $_POST['photo_watermark_size'], 'fill' => 'resize', 'file' => $_SERVER["DOCUMENT_ROOT"] . $_POST['photo_watermark_path'], 'alpha_level' => $_POST['photo_watermark_opacity'], 'use_copyright' => $_POST["photo_watermark_copyright"] == "Y" ? "Y" : "N"); } else { $arWatermark = array(); } $arIds = array(); for ($i = 0; $i < $file_count; $i++) { $Info = array('name' => $files['name'][$i], 'filename' => $files['name'][$i], 'description' => '', 'tags' => ''); $arFiles = array(); $name_i = $files['name'][$i]; $type_i = $files['type'][$i]; $tmp_name_i = $files['tmp_name'][$i]; $error_i = $files['error'][$i]; $size_i = $files['size'][$i]; if ($size_i > 0 && $arParams["UPLOAD_MAX_FILE_SIZE"] > 0 && $size_i > $arParams["UPLOAD_MAX_FILE_SIZE"]) { CImageUploader::SaveError(array(array("file" => $name_i, "id" => "BXPH_FUNC_HANDLE_LARGE_SIZE", "text" => GetMessage('P_WM_IMG_ERROR04')))); continue; } if ($type_i && strpos(strtolower($type_i), 'image') === false) { CImageUploader::SaveError(array(array("file" => $name_i, "id" => "BXPH_FUNC_HANDLE_TYPE", "text" => GetMessage('P_WM_IMG_ERROR02')))); continue; } $ext_i = GetFileExtension($name_i); $name_i = GetFileNameWithoutExtension($name_i); $name_i_ = preg_replace("/[^a-zA-Z0-9_]/i", "", $name_i); if ($name_i_ != $name_i) { $name_i = ($name_i_ == '' ? substr(md5(mt_rand()), 0, 6) : '') . $name_i_; } // TODO: exif, iptc //$exif = CFile::ExtractImageExif($tmp_name_i); //$iptc = CFile::ExtractImageIPTC($tmp_name_i); $thumbSize = round($arParams["THUMBNAIL_SIZE"] * 1.8); foreach ($arParams['converters'] as $key => $val) { $destPath = $sTmpPath . $name_i . "_" . $key . "." . $ext_i; if ($val["code"] == "real_picture") { $size = intVal($_POST['photo_resize_size']); if ($arParams['ORIGINAL_SIZE'] && $arParams['ORIGINAL_SIZE'] > 0 && ($arParams['ORIGINAL_SIZE'] < $size || $size <= 0)) { $size = $arParams['ORIGINAL_SIZE']; } $arSize = array('width' => $size, 'height' => $size); $jpegQuality = $arParams['JPEG_QUALITY']; } else { if ($val["code"] == "thumbnail") { $arSize = array('width' => $thumbSize, 'height' => $thumbSize); $jpegQuality = $arParams['JPEG_QUALITY1']; } else { $arSize = array('width' => intVal($val['width']), 'height' => intVal($val['height'])); } } if (!$jpegQuality || $jpegQuality < 20) { $jpegQuality = false; } $arCurWatermark = $arSize['width'] > $arParams['WATERMARK_MIN_PICTURE_SIZE'] || $arSize['height'] > $arParams['WATERMARK_MIN_PICTURE_SIZE'] ? $arWatermark : array(); $res = CFile::ResizeImageFile($tmp_name_i, $destPath, $arSize, BX_RESIZE_IMAGE_PROPORTIONAL_ALT, $arCurWatermark, $jpegQuality, array()); $arFiles[] = array('name' => $files['name'][$i], 'tmp_name' => $destPath, 'errors' => $files['error'][$i], 'type' => $files['type'][$i], 'size' => '', 'mode' => $val["code"], 'width' => '', 'height' => '', 'path' => $destPath); } $elementId = handleFile($Info, $arFiles, array('arParams' => $arParams, "~arResult" => $arResult)); if ($elementId) { $arIds[] = $elementId; } foreach ($arFiles as $arFile) { if (file_exists($arFile['tmp_name'])) { unlink($arFile['tmp_name']); } } } $jsResFiles = array(); if (count($arIds) > 0) { $rsElement = CIBlockElement::GetList(array(), array("ID" => $arIds), false, false, array("ID", "PREVIEW_PICTURE")); while ($arElement = $rsElement->Fetch()) { $arFile = CFile::GetFileArray($arElement["PREVIEW_PICTURE"]); $jsResFiles[$arFile['ORIGINAL_NAME']] = array('ID' => $arElement["ID"], 'PATH' => $arFile['SRC'], 'WIDTH' => $arFile['WIDTH'], 'HEIGHT' => $arFile['HEIGHT'], 'NAME' => $arFile['FILE_NAME']); } } $savedData = CImageUploader::GetSavedData(); if ($savedData['NEW_SECTION_NAME'] && $savedData['SECTION_ID'] > 0) { $newSectionName = $savedData['NEW_SECTION_NAME']; unset($savedData['NEW_SECTION_NAME']); CImageUploader::SetSavedData($savedData); } onAfterUpload(array('arParams' => $arParams, "~arResult" => $arResult)); // Update redirect url $REDIRECT_URL = CComponentEngine::MakePathFromTemplate($arParams["~SECTION_URL"], array("USER_ALIAS" => $arParams["USER_ALIAS"], "SECTION_ID" => $savedData["SECTION_ID"])); //$REDIRECT_URL = $REDIRECT_URL.(strpos($REDIRECT_URL, "?") === false ? "?" : "&")."uploader_redirect=Y&sessid=".bitrix_sessid(); ?> <script>top.bxiu_simple_res = { error: <?php if ($savedData['arError'] && count($savedData['arError']) > 0) { echo CUtil::PhpToJSObject($savedData['arError']); } else { echo '""'; } ?> , files: <?php echo CUtil::PhpToJSObject($jsResFiles); ?> , redirectUrl: '<?php echo CUtil::JSEscape($REDIRECT_URL); ?> ' <?php if (!empty($newSectionName)) { ?> ,newSection: { id: <?php echo intVal($savedData['SECTION_ID']); ?> , title: '<?php echo CUtil::JSEscape($newSectionName); ?> ' } <?php } ?> };</script> <?php $savedData['arError'] = array(); CImageUploader::SetSavedData($savedData); die; }
function WatermarkImage(&$obj, $Params = array()) { $file = $Params['file']; if (!$obj || empty($file) || !file_exists($file) || !is_file($file) || !function_exists("gd_info")) { return false; } $arFile = array("ext" => GetFileExtension($file)); $Params["width"] = intval(@imagesx($obj)); $Params["height"] = intval(@imagesy($obj)); $Params["coefficient"] = floatval($Params["coefficient"]); if (!isset($Params["alpha_level"])) { $Params["alpha_level"] = 100; } $Params["alpha_level"] = intval($Params["alpha_level"]) / 100; $wmWidth = round($Params["width"] * $Params["coefficient"]); $wmHeight = round($Params["height"] * $Params["coefficient"]); $arFileSizeTmp = CFile::GetImageSize($file); if (!in_array($arFileSizeTmp[2], array(IMAGETYPE_PNG, IMAGETYPE_JPEG, IMAGETYPE_GIF, IMAGETYPE_BMP))) { return false; } if ($Params["fill"] == 'resize') { $file_obj_1 = CFile::CreateImage($file, $arFileSizeTmp[2]); $arFile["width"] = intval(imagesx($file_obj_1)); $arFile["height"] = intval(imagesy($file_obj_1)); if ($arFile["width"] > $wmWidth || $arFile["height"] > $wmHeight) { $file_1 = $file . '_new.tmp'; CFile::ResizeImageFile($file, $file_1, array('width' => $wmWidth, 'height' => $wmHeight)); $file_obj = CFile::CreateImage($file_1, $arFileSizeTmp[2]); @imagedestroy($file_obj_1); } else { $file_obj = $file_obj_1; } } else { $file_obj = CFile::CreateImage($file, $arFileSizeTmp[2]); if ($Params["fill"] == 'repeat') { $Params["position"] = array('x' => 'top', 'y' => 'left'); } } if (!$file_obj) { return false; } $arFile["width"] = intval(@imagesx($file_obj)); $arFile["height"] = intval(@imagesy($file_obj)); $wm_pos = array("x" => 2, "y" => 2, "width" => $arFile["width"], "height" => $arFile["height"]); if ($Params["position"]['y'] == 'center') { $wm_pos["y"] = intval(($Params["height"] - $wm_pos["height"]) / 2); } elseif ($Params["position"]['y'] == 'bottom') { $wm_pos["y"] = intval($Params["height"] - $wm_pos["height"]); } if ($Params["position"]['x'] == 'center') { $wm_pos["x"] = intval(($Params["width"] - $wm_pos["width"]) / 2); } elseif ($Params["position"]['x'] == 'right') { $wm_pos["x"] = intval($Params["width"] - $wm_pos["width"]); } if ($wm_pos["y"] < 2) { $wm_pos["y"] = 2; } if ($wm_pos["x"] < 2) { $wm_pos["x"] = 2; } for ($y = 0; $y < $arFile["height"]; $y++) { for ($x = 0; $x < $arFile["width"]; $x++) { $watermark_y = $wm_pos["y"] + $y; while (true) { $watermark_x = $wm_pos["x"] + $x; while (true) { $return_color = NULL; $watermark_alpha = $Params["alpha_level"]; $main_rgb = imagecolorsforindex($obj, imagecolorat($obj, $watermark_x, $watermark_y)); $watermark_rbg = imagecolorsforindex($file_obj, imagecolorat($file_obj, $x, $y)); if ($watermark_rbg['alpha']) { $watermark_alpha = round((127 - $watermark_rbg['alpha']) / 127, 2); $watermark_alpha = $watermark_alpha * $Params["alpha_level"]; } $res = array(); foreach (array('red', 'green', 'blue', 'alpha') as $k) { $res[$k] = round($main_rgb[$k] * (1 - $watermark_alpha) + $watermark_rbg[$k] * $watermark_alpha); } $return_color = imagecolorexactalpha($obj, $res["red"], $res["green"], $res["blue"], $res["alpha"]); if ($return_color == -1) { $return_color = imagecolorallocatealpha($obj, $res["red"], $res["green"], $res["blue"], $res["alpha"]); if ($return_color == -1) { $return_color = imagecolorclosestalpha($obj, $res["red"], $res["green"], $res["blue"], $res["alpha"]); } } imagesetpixel($obj, $watermark_x, $watermark_y, $return_color); $watermark_x += $arFile["width"]; if ($Params["fill"] != 'repeat' || $watermark_x > $Params["width"]) { break; } } $watermark_y += $arFile["height"]; if ($Params["fill"] != 'repeat' || $watermark_y > $Params["height"]) { break; } } } } @imagedestroy($file_obj); return true; }
$arResult['SIZE'] .= ' height="' . $arResult['HEIGHT'] . '"'; } } else { $arResult['NOT_USE_SIZES'] = 'Y'; } if ($arParams['INCLUDE_TYPE'] == 'D' && $arParams['USE_THUMBNAIL'] == 'Y') { $arResult['THUMBNAIL'] = array(); $arResult['USE_THUMBNAIL'] = 'Y'; if ($arParams['THUMB_NOT_USE_SIZES'] != 'Y' && $arParams['THUMB_WIDTH'] != $image[0] && $arParams['THUMB_HEIGHT'] != $image[1] && ($arParams['THUMB_WIDTH'] > 0 || $arParams['THUMB_HEIGHT'] > 0)) { $proportions = array("landscape" => $image[0] / $image[1], 'portrait' => $image[1] / $image[0]); $values = array("width" => round($arParams['THUMB_HEIGHT'] * $proportions['landscape']), 'height' => round($arParams['THUMB_WIDTH'] * $proportions['portrait'])); $thumb_sizes = array('width' => $arParams['THUMB_WIDTH'] ? $arParams['THUMB_WIDTH'] : $values['width'], 'height' => $arParams['THUMB_HEIGHT'] ? $arParams['THUMB_HEIGHT'] : $values['height']); if (!$arResult['FILE_ID']) { $destfile = $rootpathinfo['dirname'] . '/' . $rootpathinfo['filename'] . '_' . $arParams['THUMB_WIDTH'] . 'x' . $arParams['THUMB_HEIGHT'] . $rootpathinfo['extension']; $thumbSrc = $pathinfo['dirname'] . '/' . $rootpathinfo['filename'] . '_' . $arParams['THUMB_WIDTH'] . 'x' . $arParams['THUMB_HEIGHT'] . $rootpathinfo['extension']; CFile::ResizeImageFile($arResult['ROOT_FILE'], $destfile, $thumb_sizes, BX_RESIZE_IMAGE_PROPORTIONAL); $thumb['src'] = $thumbSrc; } else { $thumb = CFile::ResizeImageGet($arResult['FILE_ID'], $thumb_sizes, BX_RESIZE_IMAGE_PROPORTIONAL); } $arResult['THUMBNAIL']['SRC'] = $thumb['src']; $arResult['THUMBNAIL']['WIDTH'] = $thumb_sizes['width']; $arResult['THUMBNAIL']['HEIGHT'] = $thumb_sizes['height']; $arResult['THUMBNAIL_SIZE'] = ''; if ($arResult['THUMBNAIL']['WIDTH'] > 0) { $arResult['THUMBNAIL']['SIZE'] .= 'width="' . $arResult['THUMBNAIL']['WIDTH'] . '"'; } if ($arResult['THUMBNAIL']['HEIGHT'] > 0) { $arResult['THUMBNAIL']['SIZE'] .= ' height="' . $arResult['THUMBNAIL']['HEIGHT'] . '"'; } }