S
S
sagaton2022-04-21 11:54:01
1C-Bitrix
sagaton, 2022-04-21 11:54:01

How to resize an image?

How to resize an image if there is only one array with the path to the image?

[PREVIEW_PICTURE_SRC] => /upload/iblock/0ff/jvdg3y94o8fhfgjmzxj0c3vodb7eosd8.png

Tried something like this
$resize = CFile::ResizeImageGet(
        $img['PREVIEW_PICTURE_SRC'],
        Array('width'=>260,
            'height'=>260),
        BX_RESIZE_IMAGE_EXACT,
        true
    );

But to apply it is usually used like this
$arResult["ITEMS"][$key]['PREVIEW_PICTURE']['SRC'] = $resize['src'];

but how to apply in this case? If there is no ['src'] but only ['PREVIEW_PICTURE_SRC']

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
nikolay22323, 2022-04-21
@nikolay22323

Slaughter him with imagemagick

T
tgarl, 2022-04-21
@tgarl

And who prevents you from assigning the resulting value to any key convenient for you and using it already?

$arResult["ITEMS"][$key]['NEW_PREVIEW_PICTURE_SRC'] = $resize['src'];

and in the template fix the key to your new one

P
PetrPo, 2022-04-22
@PetrPo

Well, it's certainly PPC how strange, but somehow

$resize = [];

$filePath = '/upload/iblock/0ff/jvdg3y94o8fhfgjmzxj0c3vodb7eosd8.png';
$arFilePath = explode('/', $filePath);
$fileName = $arFilePath[array_key_last($arFilePath)];

$iterator = \Bitrix\Main\FileTable::getList([
  'select' => ['ID'],
  'filter' => ['FILE_NAME' => $fileName],
]);

if($row = $iterator->fetch()) {
  $resize = CFile::ResizeImageGet($row['ID'], ['width'=>260, 'height'=>260], BX_RESIZE_IMAGE_EXACT, true);
}

print_r($resize);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question