本文整理汇总了PHP中CFile::ResizeImage方法的典型用法代码示例。如果您正苦于以下问题:PHP CFile::ResizeImage方法的具体用法?PHP CFile::ResizeImage怎么用?PHP CFile::ResizeImage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CFile
的用法示例。
在下文中一共展示了CFile::ResizeImage方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: Edit
public static function Edit($Params)
{
global $DB;
$source_id = false;
$arFields = $Params['arFields'];
$bNew = !isset($arFields['ID']) || $arFields['ID'] <= 0;
$bFile_FD = $Params['path'] && strlen($Params['path']) > 0;
$bFile_PC = $Params['file'] && strlen($Params['file']['name']) > 0 && $Params['file']['size'] > 0;
$io = CBXVirtualIo::GetInstance();
if ($bFile_FD || $bFile_PC) {
if ($bFile_FD) {
$DocRoot = CSite::GetSiteDocRoot(false);
$tmp_name = $DocRoot . $Params['path'];
if ($io->FileExists($tmp_name)) {
$flTmp = $io->GetFile($tmp_name);
$file_name = substr($Params['path'], strrpos($Params['path'], '/') + 1);
$arFile = array("name" => $file_name, "size" => $flTmp->GetFileSize(), "tmp_name" => $tmp_name, "type" => CFile::IsImage($file_name) ? 'image' : 'file');
}
} else {
if ($bFile_PC) {
$arFile = $Params['file'];
}
}
if (!CMedialib::CheckFileExtention($arFile["name"])) {
return false;
}
if (!$bNew) {
$arFile["old_file"] = CMedialibItem::GetSourceId($arFields['ID']);
$arFile["del"] = "Y";
}
// Resizing Image
if (CFile::IsImage($arFile["name"])) {
$arSize = array('width' => COption::GetOptionInt('fileman', "ml_max_width", 1024), 'height' => COption::GetOptionInt('fileman', "ml_max_height", 1024));
$res = CFile::ResizeImage($arFile, $arSize);
}
$arFile["MODULE_ID"] = "fileman";
$source_id = CFile::SaveFile($arFile, "medialibrary");
if ($source_id) {
$r = CFile::GetByID($source_id);
if ($arFile = $r->Fetch()) {
if (CFile::IsImage($arFile['FILE_NAME'])) {
CMedialibItem::GenerateThumbnail($arFile, array('width' => COption::GetOptionInt('fileman', "ml_thumb_width", 140), 'height' => COption::GetOptionInt('fileman', "ml_thumb_height", 105)));
}
$arFile['PATH'] = CMedialibItem::GetFullPath($arFile);
}
}
}
// TODO: Add error handling
if ($bNew && !$source_id) {
return false;
}
// 2. Add to b_medialib_item
if (!isset($arFields['~DATE_UPDATE'])) {
$arFields['~DATE_UPDATE'] = $DB->CurrentTimeFunction();
}
if (!CMedialibItem::CheckFields($arFields)) {
return false;
}
if (CModule::IncludeModule("search")) {
$arStem = stemming($arFields['NAME'] . ' ' . $arFields['DESCRIPTION'] . ' ' . $arFields['KEYWORDS'], LANGUAGE_ID);
if (count($arStem) > 0) {
$arFields['SEARCHABLE_CONTENT'] = '{' . implode('}{', array_keys($arStem)) . '}';
} else {
$arFields['SEARCHABLE_CONTENT'] = '';
}
}
if ($bNew) {
unset($arFields['ID']);
$arFields['SOURCE_ID'] = $source_id;
$arFields['~DATE_CREATE'] = $arFields['~DATE_UPDATE'];
$arFields['ITEM_TYPE'] = '';
$ID = CDatabase::Add("b_medialib_item", $arFields, array("DESCRIPTION", "SEARCHABLE_CONTENT"));
} else {
if ($source_id) {
$arFields['SOURCE_ID'] = $source_id;
}
$ID = $arFields['ID'];
unset($arFields['ID']);
$strUpdate = $DB->PrepareUpdate("b_medialib_item", $arFields);
$strSql = "UPDATE b_medialib_item SET " . $strUpdate . " WHERE ID=" . IntVal($ID);
$DB->QueryBind($strSql, array("DESCRIPTION" => $arFields["DESCRIPTION"], "SEARCHABLE_CONTENT" => $arFields["SEARCHABLE_CONTENT"]), false, "File: " . __FILE__ . "<br>Line: " . __LINE__);
}
// 3. Set fields to b_medialib_collection_item
if (!$bNew) {
$strSql = "DELETE FROM b_medialib_collection_item WHERE ITEM_ID=" . IntVal($ID);
$DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
}
$strCollections = "0";
for ($i = 0, $l = count($Params['arCollections']); $i < $l; $i++) {
$strCollections .= "," . IntVal($Params['arCollections'][$i]);
}
$strSql = "INSERT INTO b_medialib_collection_item(ITEM_ID, COLLECTION_ID) " . "SELECT " . intVal($ID) . ", ID " . "FROM b_medialib_collection " . "WHERE ID in (" . $strCollections . ")";
$res = $DB->Query($strSql, false, "FILE: " . __FILE__ . "<br> LINE: " . __LINE__);
if (!$arFields['ID']) {
$arFields['ID'] = $ID;
}
if ($source_id) {
$arFields = array_merge($arFile, $arFields);
}
return $arFields;
//.........这里部分代码省略.........
示例2: CheckFields
function CheckFields($ACTION, &$arFields, $ID = false)
{
if (is_set($arFields, "AVATAR") && strlen($arFields["AVATAR"]["name"]) <= 0 && strlen($arFields["AVATAR"]["del"]) <= 0) {
unset($arFields["AVATAR"]);
}
$aMsg = array();
// Checking user for updating or adding
// USER_ID as value
if ((is_set($arFields, "USER_ID") || $ACTION == "ADD") && intVal($arFields["USER_ID"]) <= 0) {
$aMsg[] = array("id" => 'EMPTY_USER_ID', "text" => GetMessage("F_GL_ERR_EMPTY_USER_ID"));
} elseif (is_set($arFields, "USER_ID")) {
$user = CUser::GetByID($arFields["USER_ID"])->fetch();
if (empty($user)) {
$aMsg[] = array("id" => 'USER_DOES_NOT_EXIST', "text" => GetMessage("F_GL_ERR_USER_NOT_EXIST", array("#UID#" => htmlspecialcharsbx($arFields["USER_ID"]))));
}
$res = CForumUser::GetByUSER_ID($arFields["USER_ID"]);
if ($ACTION == "UPDATE") {
unset($arFields["USER_ID"]);
} else {
if (!empty($res)) {
$aMsg[] = array("id" => 'USER_EXISTS', "text" => GetMessage("F_GL_ERR_USER_IS_EXIST", array("#UID#" => htmlspecialcharsbx($arFields["USER_ID"]))));
} else {
if (!array_key_exists("AVATAR", $arFields) && $user["PERSONAL_PHOTO"] > 0) {
$arFields["AVATAR"] = CFile::MakeFileArray($user["PERSONAL_PHOTO"]);
if (!$arFields["AVATAR"] || CFile::ResizeImage($arFields["AVATAR"], array("width" => COption::GetOptionInt("forum", "avatar_max_width", 100), "height" => COption::GetOptionInt("forum", "avatar_max_height", 100)))) {
unset($arFields["AVATAR"]);
}
}
}
}
}
// last visit
if (is_set($arFields, "LAST_VISIT")) {
$arFields["LAST_VISIT"] = trim($arFields["LAST_VISIT"]);
if (strLen($arFields["LAST_VISIT"]) > 0) {
if ($arFields["LAST_VISIT"] != $GLOBALS["DB"]->GetNowFunction() && !$GLOBALS["DB"]->IsDate($arFields["LAST_VISIT"], false, SITE_ID, "FULL")) {
$aMsg[] = array("id" => 'LAST_VISIT', "text" => GetMessage("F_GL_ERR_LAST_VISIT"));
}
} else {
unset($arFields["LAST_VISIT"]);
}
}
// date registration
if (is_set($arFields, "DATE_REG")) {
$arFields["DATE_REG"] = trim($arFields["DATE_REG"]);
if (strLen($arFields["DATE_REG"]) > 0) {
if ($arFields["DATE_REG"] != $GLOBALS["DB"]->GetNowFunction() && !$GLOBALS["DB"]->IsDate($arFields["DATE_REG"], false, SITE_ID, "SHORT")) {
$aMsg[] = array("id" => 'DATE_REG', "text" => GetMessage("F_GL_ERR_DATE_REG"));
}
} else {
unset($arFields["DATE_REG"]);
}
}
// avatar
if (is_set($arFields, "AVATAR")) {
$max_size = COption::GetOptionInt("forum", "file_max_size", 5242880);
$size = array("width" => COption::GetOptionInt("forum", "avatar_max_width", 100), "height" => COption::GetOptionInt("forum", "avatar_max_height", 100));
$res = CFile::CheckImageFile($arFields["AVATAR"], $max_size);
if (strlen($res) <= 0) {
$res = CFile::CheckImageFile($arFields["AVATAR"], $max_size, $size["width"], $size["height"]);
if (strlen($res) > 0 && CFile::ResizeImage($arFields["AVATAR"], $size)) {
$res = '';
}
}
if (strlen($res) > 0) {
$aMsg[] = array("id" => 'AVATAR', "text" => $res);
}
}
if (!empty($aMsg)) {
$e = new CAdminException(array_reverse($aMsg));
$GLOBALS["APPLICATION"]->ThrowException($e);
return false;
}
// show name
if (is_set($arFields, "SHOW_NAME") || $ACTION == "ADD") {
if (empty($arFields["SHOW_NAME"])) {
$arFields["SHOW_NAME"] = COption::GetOptionString("forum", "USER_SHOW_NAME", "Y") == "Y" ? "Y" : "N";
}
$arFields["SHOW_NAME"] = $arFields["SHOW_NAME"] == "N" ? "N" : "Y";
}
// allow post
if (is_set($arFields, "ALLOW_POST") || $ACTION == "ADD") {
$arFields["ALLOW_POST"] = $arFields["ALLOW_POST"] == "N" ? "N" : "Y";
}
return True;
}
示例3: AddImage
/**
* <p>Метод привязывает изображение к Wiki-странице. Динамичный метод.</p>
*
*
* @param int $ID Идентификатор Wiki-страницы. До версии 10.0.0 назывался <b>ELEMENT_ID</b>.
*
* @param int $IBLOCK_ID Идентификатор Инфо.блока
*
* @param array $arImage Массив свойств изображения
*
* @return int
*
* <h4>Example</h4>
* <pre>
* <?<br>
* // привяжем изображение к странице с идентификатором 13 из инфо.блока с идентификатором 2
* $ID = 13;
* $IBLOCK_ID = 2;
*
* if (CFile::IsImage($_FILES['FILE_ID']['name']))
* {
* $CWiki = new CWiki();
* $CWiki->AddImage($ID, $IBLOCK_ID, $_FILES['FILE_ID']);
* }<br>?>
* </pre>
*
*
* <h4>See Also</h4>
* <ul> <li> <a href="http://dev.1c-bitrix.ru/api_help/wiki/classes/cwiki/DeleteImage.php">CWiki::DeleteImage</a> </li>
* </ul><a name="examples"></a>
*
*
* @static
* @link http://dev.1c-bitrix.ru/api_help/wiki/classes/cwiki/AddImage.php
* @author Bitrix
*/
public function AddImage($ID, $IBLOCK_ID, $arImage)
{
$arProperties = array();
$arCurImages = array();
$arCurImagesNew = array();
$arAddImage = array();
$rsProperties = CIBlockElement::GetProperty($IBLOCK_ID, $ID, 'value_id', 'asc', array('ACTIVE' => 'Y', 'CODE' => 'IMAGES'));
while ($arProperty = $rsProperties->Fetch()) {
if ($arProperty['CODE'] == 'IMAGES') {
$arProperties['IMAGES'] = $arProperty;
$arCurImages[] = $arProperty['VALUE'];
}
}
$obProperty = new CIBlockProperty();
$res = true;
if (!array_key_exists('IMAGES', $arProperties)) {
$res = $obProperty->Add(array('IBLOCK_ID' => $IBLOCK_ID, 'ACTIVE' => 'Y', 'PROPERTY_TYPE' => 'F', 'MULTIPLE' => 'Y', 'NAME' => 'Images', 'CODE' => 'IMAGES'));
}
$arFields = array();
CFile::ResizeImage($arImage, array('width' => COption::GetOptionString('wiki', 'image_max_width', 600), 'height' => COption::GetOptionString('wiki', 'image_max_height', 600)));
$arFields['PROPERTY_VALUES'] = array('IMAGES' => $arImage);
$arFields['BLOCK_ID'] = $IBLOCK_ID;
$arFields['ELEMENT_ID'] = $ID;
$this->cIB_E->Update($ID, $arFields);
$rsProperties = CIBlockElement::GetProperty($IBLOCK_ID, $ID, 'value_id', 'asc', array('ACTIVE' => 'Y', 'CODE' => 'IMAGES', 'EMPTY' => 'N'));
while ($arProperty = $rsProperties->Fetch()) {
if ($arProperty['CODE'] == 'IMAGES') {
$arCurImagesNew[] = $arProperty['VALUE'];
}
}
$arAddImage = array_diff($arCurImagesNew, $arCurImages);
list(, $imgId) = each($arAddImage);
return $imgId;
}
示例4: array
}
$arResult["ShowForm"] = "Input";
$arResult["ErrorFields"] = array();
if ($_SERVER["REQUEST_METHOD"] == "POST" && strlen($_POST["save"]) > 0 && check_bitrix_sessid()) {
if ($_POST["ajax_request"] == "Y") {
CUtil::JSPostUnescape();
}
$errorMessage = "";
$warningMessage = "";
if (!array_key_exists("TAB", $arResult) || $arResult["TAB"] == "edit") {
if (intval($_POST["GROUP_IMAGE_ID"]) > 0) {
if (intval($arResult["POST"]["IMAGE_ID"]) != intval($_POST["GROUP_IMAGE_ID"]) && in_array($_POST['GROUP_IMAGE_ID'], \Bitrix\Main\UI\FileInputUtility::instance()->checkFiles('GROUP_IMAGE_ID', array($_POST['GROUP_IMAGE_ID'])))) {
$arImageID = CFile::MakeFileArray($_POST["GROUP_IMAGE_ID"]);
$arImageID["old_file"] = $arResult["POST"]["IMAGE_ID"];
$arImageID["del"] = "N";
CFile::ResizeImage($arImageID, array("width" => 300, "height" => 300), BX_RESIZE_IMAGE_PROPORTIONAL);
}
} else {
$arImageID = array("del" => "Y", "old_file" => $arResult["POST"]["IMAGE_ID"]);
}
$arResult["POST"]["NAME"] = htmlspecialcharsbx($_POST["GROUP_NAME"]);
$arResult["POST"]["DESCRIPTION"] = $_POST["GROUP_DESCRIPTION"];
$arResult["POST"]["IMAGE_ID_DEL"] = $_POST["GROUP_IMAGE_ID_DEL"] == "Y" ? "Y" : "N";
$arResult["POST"]["SUBJECT_ID"] = $_POST["GROUP_SUBJECT_ID"];
$arResult["POST"]["VISIBLE"] = $_POST["GROUP_VISIBLE"] == "Y" ? "Y" : "N";
$arResult["POST"]["OPENED"] = $_POST["GROUP_OPENED"] == "Y" ? "Y" : "N";
$arResult["POST"]["IS_EXTRANET_GROUP"] = $_POST["IS_EXTRANET_GROUP"] == "Y" ? "Y" : "N";
$arResult["POST"]["EXTRANET_INVITE_ACTION"] = isset($_POST["EXTRANET_INVITE_ACTION"]) && $_POST["EXTRANET_INVITE_ACTION"] == "add" ? "add" : "invite";
$arResult["POST"]["CLOSED"] = $_POST["GROUP_CLOSED"] == "Y" ? "Y" : "N";
$arResult["POST"]["KEYWORDS"] = $_POST["GROUP_KEYWORDS"];
$arResult["POST"]["INITIATE_PERMS"] = $_POST["GROUP_INITIATE_PERMS"];
示例5: getFrameAsData
public static function getFrameAsData($file, $width, $height, $seconds, $for_html = true, $use_cache = true)
{
if ($program = static::findProgram("ffmpeg")) {
if (file_exists($file)) {
$param_string = serialize(func_get_args());
//$hash = sha1(md5_file($file).md5($param_string));
$time = static::seconds_to_format($seconds);
$output = abs_path("/upload/frames/out" . md5($param_string) . ".jpg");
if ($use_cache) {
$result = static::getCache(__FUNCTION__ . $param_string);
}
if (empty($result['RESULT'])) {
$comm = $program . " -ss {$time} -i {$file} -frames:v 1 {$output}";
exec($comm);
if (file_exists($output)) {
if (intval($width) && intval($height)) {
$obFile = new CFile();
$arFile = \CFile::MakeFileArray($output);
$checkfile = $obFile->CheckFile($arFile, 400000, 'image/', 'gif,png,jpeg,jpg');
if (empty($checkfile)) {
$obFile->ResizeImage($arFile, array("width" => $width, "height" => $height), BX_RESIZE_IMAGE_EXACT);
$output = $arFile['tmp_name'];
}
}
$base64data = static::getBase64File($output, $for_html);
if (!empty($base64data)) {
$result['RESULT'] = $base64data;
unlink($output);
static::setCache(__FUNCTION__ . $param_string, $result['RESULT']);
}
}
}
return $result['RESULT'];
}
}
return false;
}