Skip to content

Instantly share code, notes, and snippets.

@SergeyZaigraev
Last active October 16, 2023 03:52
Show Gist options
  • Save SergeyZaigraev/b0db247ef52c4822570986334567679a to your computer and use it in GitHub Desktop.
Save SergeyZaigraev/b0db247ef52c4822570986334567679a to your computer and use it in GitHub Desktop.
Bitrix resize image IB. Ресайз изображений инфоблока. Например можно изменить размер картинки анонса у всех товаров. Скрипт пошаговый.
<?php
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php");
$iblockId = (int)$_REQUEST['iblock'];
$page = isset($_REQUEST['page']) ? (int)$_REQUEST['page'] : 1;
$pageSize = 70;
$isEnd = true;
if ($iblockId <= 0)
{
ShowError('need define iblock id request');
}
else if (!$USER->IsAdmin())
{
ShowError('access denied');
}
else if (!\Bitrix\Main\Loader::includeModule('iblock') && !\Bitrix\Main\Loader::includeModule('main'))
{
ShowError('require iblock');
}
else
{
$query = \CIBlockElement::GetList(
array(
'ID' => 'ASC'
),
array(
'IBLOCK_ID' => $iblockId,
),
false,
array(
'iNumPage' => $page,
'nPageSize' => $pageSize
),
array(
'IBLOCK_ID',
'ID',
'PREVIEW_PICTURE',
'DETAIL_PICTURE',
)
);
$index = ($page - 1) * $pageSize;
$el = new CIBlockElement();
while ($item = $query->Fetch())
{
// $newPict = !$item['PREVIEW_PICTURE'] ? $item['DETAIL_PICTURE']: $item['PREVIEW_PICTURE'];
$newPict = $item['DETAIL_PICTURE'];
$newPictArr = CFile::GetFileArray($newPict);
$src = CFile::MakeFileArray($newPictArr['SRC']);
$src['COPY_FILE'] = 'Y';
$res = $el->Update($item['ID'], array("PREVIEW_PICTURE" => $src),false,false,true);
$index++;
}
$isEnd = ($index >= $query->SelectedRowsCount());
}
if ($isEnd)
{
echo 'Ready!';
}
else
{
$url = $APPLICATION->GetCurPageParam('page=' . ($page + 1), array('page'));
echo 'Progress...';
?>
<script>
setTimeout(function() {
window.location = <?= json_encode($url); ?>;
}, 1000);
</script>
<?
}
require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/epilog_after.php");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment