Skip to content

Instantly share code, notes, and snippets.

@nafilimonov
Last active June 30, 2018 08:33
Show Gist options
  • Save nafilimonov/984a5c11169fc09acf928e5880a10642 to your computer and use it in GitHub Desktop.
Save nafilimonov/984a5c11169fc09acf928e5880a10642 to your computer and use it in GitHub Desktop.
Bitrix. Iblock. Скрипт для уменьшения картинок в PREVIEW_PICTURE
<?php
namespace Grizzly;
use Bitrix\Main\Loader;
/*
$param = array(
'id' => 38,
'width' => 1200,
'height' => 999999,
'resize' => 'DETAIL_PICTURE'
);
*/
class Images {
public $param;
public function __construct($param = array()) {
Loader::includeModule('iblock');
if ( empty($param) ) return;
$this->setParam($param);
}
public function setParam($param)
{
$this->param = $param;
}
public function getParam()
{
return $this->param;
}
public function resize($pic)
{
$image = \CFile::GetFileArray($pic);
$param = $this->getParam();
$image_src = $_SERVER['DOCUMENT_ROOT'] . $image['SRC'];
$tmp_image = $_SERVER['DOCUMENT_ROOT'] . '/upload/' . $image['FILE_NAME'];
\CFile::ResizeImageFile(
$image_src,
$tmp_image,
array('width'=>$param['width'], 'height'=>$param['height']),
BX_RESIZE_IMAGE_PROPORTIONAL
);
unlink($image_src);
rename($tmp_image, $image_src);
return;
}
public function resizeIblockImages()
{
$param = $this->getParam();
$i = 0;
$res = \CIBlockElement::GetList(
array('ID' => 'ASC'),
array('IBLOCK_ID' => $param['id']),
false,
false,
array('ID', 'IBLOCK_ID', $param['resize'])
);
while($ar_res = $res->Fetch())
{
$this->resize($ar_res[$param['resize']]);
$i++;
}
echo 'Сжато изображений: ' . $i;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment