The last notes
All English-language materials have been translated fully automatically using the Google service
Get the full path to the image in Bitrix
CFile::GetPath(315);
We get the result:
/upload/iblock/c1d/k2a29s8d47791f814gja8fd038d83790.jpg
Resize images
// We can use the following conversion constants:
//BX_RESIZE_IMAGE_EXACT —scales to rectangle $ arSize keeping proportions, cutting off excess;
//BX_RESIZE_IMAGE_PROPORTIONAL —scales proportionally, the size is limited to $ arSize;
//BX_RESIZE_IMAGE_PROPORTIONAL_ALT — scales proportionally, the size is limited to $ arSize, improved handling of vertical images.
$arFileTmp = CFile::ResizeImageGet(
$row['PREVIEW_PICTURE'],
array("width" => 1000, "height" => 1000),
BX_RESIZE_IMAGE_PROPORTIONAL,
true
);
echo $arFileTmp["src"];
Upload and update image
Form an array from the loaded image. For example, to update the image in the product
$arFile = CFile::MakeFileArray($_SERVER["DOCUMENT_ROOT"]."PATH_TO_IMAGE");
Returns an array of the following type
Array
(
[name] => caa99553003f620f2b1ed91ebb7129e1.jpg
[size] => 913948
[tmp_name] => /home/bitrix/www/upload/tmp/434/caa99553003f620f2b1ed91ebb7129e1.jpg
[type] => image/jpeg
)
Let's update, for example, the photo of the section
$arFile = CFile::MakeFileArray('PATH_TO_IMAGE');
// To get the data array of the already loaded image
// Let's use the following construction
//$arFile = CFile::GetFileArray('ID_OF_IMAGE');
$arPICTURE = $arFile;
$arPICTURE["MODULE_ID"] = "iblock";
$bs = new CIBlockSection;
$arFields = Array(
"PICTURE" => $arPICTURE,
);
//$ar_result['ID'] -ID of the section being updated
$res = $bs->Update($ar_result['ID'], $arFields, false, false, true);
Removing PREVIEW_PICTURE or DETAIL_PICTURE
$el = new \CIBlockElement;
$el->Update($ELEMENT_ID, array(
"PREVIEW_PICTURE" => array('del' => 'Y'),
"DETAIL_PICTURE" => array('del' => 'Y'),
), false, false);
Removing photos from MORE_PHOTO
\CIBlockElement::SetPropertyValuesEx($ELEMENT_ID, $IBLOCK_ID, array("MORE_PHOTO" => array("VALUE" => array("del" => "Y"))));
Comments