ResizeImageGet
array CFile::ResizeImageGet( mixed file, array arSize, const resizeType = BX_RESIZE_IMAGE_PROPORTIONAL, bool bInitSizes = false, array arFilters = false, bool bImmediate = false, bool jpgQuality = false );
The method reduces the image and places the reduced copy into the /upload/resize_cache/path folder. Once the image is reduced, the resulting physical file that allows to avoid further operations of reducing image size in the next method calls. When calling the method again the method returns path to reduced file. Static method.
Parameters
Parameter | Description | Available from version |
---|---|---|
file | File ID from the b_file table or the file description array (Array(FILE_NAME, SUBDIR, WIDTH, HEIGHT, CONTENT_TYPE)), retrieved by the GetFileArray method. | |
Size | Array in the Array("width"=>WIDTH, "height"=>HEIGHT) format with width and height values for the reduced image. Both keys are required. | |
resizeType | Type of resizing:
| |
InitSizes | Flag that specifies if the modified image size data is returned in the resulting array. True - returns the size data, false - size data is not returned | |
Filters | Array of arrays for post-processing of the image via the following filters: array(array("name" => "sharpen", "precision" => 15)). Presently, there is only one filter - sharpen. There is no requirement to specify it - it will be initialized automatically. It is used to increase sharpness for thumbnail pictures. | |
Immediate | Flag is passed into the OnBeforeResizeImage event handler. It leads to resizing directly during the method call. Generally, the event handler can perform postponed resizing. | |
jpgQuality | Number that specifies JPG quality during resizing. The higher the value, the higher the quality and larger size of image file. |
Returned value
The method returns an array of the following type:
array( 'src', // path to reduced image relative to site root. 'width', // If bInitSizes = true, the width of reduced image is specified, otherwise 0. 'height', // If bInitSizes = true, the height of reduced image is specified, otherwise 0. )
Examples of use
//$uID - user ID $uDBInfo = CUser::GetByID($uID); if ($uInfo = $uDBInfo->GetNext()) { if ($uInfo['PERSONAL_PHOTO']) { $file = CFile::ResizeImageGet($uInfo['PERSONAL_PHOTO'], array('width'=>150, 'height'=>150), BX_RESIZE_IMAGE_PROPORTIONAL, true); $img = '<img src="'.$file['src'].'" width="'.$file['width'].'" height="'.$file['height'].'" />'; $uInfo['PERSONAL_PHOTO'] = $img; } $arResult['ITEMS'][$k]['USER_INFO'] = $uInfo; }
Watermark can be applied as follows:
$arWaterMark = Array( array( "name" => "watermark", "position" => "bottomright", // Position "type" => "image", "size" => "real", "file" => $_SERVER["DOCUMENT_ROOT"].'/upload/copy.png', // Path to image "fill" => "exact", ) ); $arFileTmp = CFile::ResizeImageGet( $arElement["DETAIL_PICTURE"], array("width" => 250, "height" => 127), BX_RESIZE_IMAGE_EXACT, true, $arWaterMark );
© «Bitrix24», 2001-2024