ResizePicture
Description
array
CIBlock::ResizePicture(
array arFile,
array arResize
);
Method executes file resizing. Static method.
Note: processes only files with format JPEG, GIF and PNG (depends on employed GD library). File specified in the parameter arFile will be rewritten.
Returned value
Array, describing file or string with error message.
See Also
Parameters
Parameter | Description |
---|---|
arFile | Array, describing the file. This can element array $_FILES[name] (or $HTTP_POST_FILES[name]), as well as result for method CFile::MakeFileArray.
From module version 14.0.0 file array is passed in the key VALUE, and description - in the key DESCRIPTION. |
arResize
| Array with sizing parameters. Contains the following keys:
|
Example
<?
AddEventHandler("iblock", "OnBeforeIBlockElementAdd", Array("MyHandlers", "ResizeElementProperty"));
AddEventHandler("iblock", "OnBeforeIBlockElementUpdate", Array("MyHandlers", "ResizeElementProperty"));
class MyHandlers
{
public static function ResizeElementProperty(&$arFields)
{
global $APPLICATION;
//Iblock code, property to be resized
$IBLOCK_ID = 1;
//Property ID
$PROPERTY_ID = 15;
//Our iblock and property values are available
if(
$arFields["IBLOCK_ID"] == $IBLOCK_ID
&& is_array($arFields["PROPERTY_VALUES"])
&& array_key_exists(15, $arFields["PROPERTY_VALUES"])
)
{
foreach($arFields["PROPERTY_VALUES"][$PROPERTY_ID] as $key => $arFile)
{
//Edit image dimensions
$arNewFile = CIBlock::ResizePicture($arFile, array(
"WIDTH" => 100,
"HEIGHT" => 100,
"METHOD" => "resample",
));
if(is_array($arNewFile))
$arFields["PROPERTY_VALUES"][$PROPERTY_ID][$key] = $arNewFile;
else
{
//can return error
$APPLICATION->throwException("Image resize error in property \"Files\":".$arNewFile);
return false;
}
}
}
}
}
?>
© «Bitrix24», 2001-2024