Documentation

ResizeImage

CFile::ResizeImage(
 array File,
 array Size,
 resizeType = BX_RESIZE_IMAGE_PROPORTIONAL
)

The method is the wrapper of ResizeImageFile. Changes sizes of image file. Static method.

Parameters

Parameter Description
Filefile array
Size Array of type array("width" => $width, "height" => $height)); both keys are required.
resizeTypetype of resizing:
  • BX_RESIZE_IMAGE_EXACT - resizes into rectangle $arSize without retaining proportions;
  • BX_RESIZE_IMAGE_PROPORTIONAL - resizes with retained proportions, size is limited by $arSize;
  • BX_RESIZE_IMAGE_PROPORTIONAL_ALT - resizes with retained proportions, size is limited by $arSize, improved processing of vertical images.

XAMPLE

Creating thumbnail images "on the go":

 $renderImage = CFile::ResizeImageGet($arResult["DETAIL_PICTURE"], Array("width" => $newWidth, "height" => $newHeight));
 echo CFile::ShowImage($renderImage['src'], $newWidth, $newHeight, "border=0", "", true);

Resizing and saving of images:

     // check file size and type.
     $checkfile = CFile::CheckFile($arFile,400000,'image/','gif,png,jpeg,jpg');
     if(strlen($checkfile) > 0) {
        $strError .= $arFile['name'].': '.$strError.'<br>';
     } else {
       // resize image
       CAllFile::ResizeImage(
          &$arFile, // path to image. Compressed file will be placed here as well.
          array(
           "width" => $newWidth,  // new width
           "height" => $newHeight // new height
          ),
          BX_RESIZE_IMAGE_EXACT // resizing method. Cropping a rectangle image disregarding the size ratio.
        );
       // save the cropped image.
       $fileId = CFile::SaveFile($arFile, $IBlockType);
     }


© «Bitrix24», 2001-2022
Up