Documentation

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:
  • WIDTH - integer. Image size will be updated so its width won't exceed the value of this field.
  • HEIGHT - integer. Image size will be updated so its height won't exceed the values of this field.
  • METHOD - possible values: resample or empty. Field value equal to "resample" results in using resizing feature imagecopyresampled, instead of imagecopyresized. This is more of a qualitative method, but requires more server resources.
  • COMPRESSION - integer from 0 to 100. When value is more than 0, it will be used as compression parameter for JPEG images. 100 corresponds to the best quality when larger file size.
Parameters METHOD and COMPRESSION are applied only if size is updated. If image meets the limits of WIDTH and HEIGHT fields, no actions are performed with the file.

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
Up