33 lines
1.0 KiB
PHP
33 lines
1.0 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Jinove\Vinoteca\Catalog;
|
|
|
|
use Bitrix\Iblock\ElementTable;
|
|
use Bitrix\Main\Loader;
|
|
|
|
final class Media
|
|
{
|
|
public static function thumbs(array $productIds, int $width, int $height): array
|
|
{
|
|
$productIds = array_values(array_unique(array_filter(array_map("intval", $productIds))));
|
|
if (!$productIds || !Loader::includeModule("iblock")) {
|
|
return [];
|
|
}
|
|
$images = [];
|
|
$rows = ElementTable::getList(["select" => ["ID", "PREVIEW_PICTURE", "DETAIL_PICTURE"], "filter" => ["=ID" => $productIds]]);
|
|
while ($row = $rows->fetch()) {
|
|
$fileId = (int)($row["DETAIL_PICTURE"] ?: $row["PREVIEW_PICTURE"]);
|
|
if ($fileId > 0) {
|
|
$resized = \CFile::ResizeImageGet($fileId, ["width" => $width, "height" => $height], BX_RESIZE_IMAGE_PROPORTIONAL, false);
|
|
if (!empty($resized["src"])) {
|
|
$images[(int)$row["ID"]] = (string)$resized["src"];
|
|
}
|
|
}
|
|
}
|
|
|
|
return $images;
|
|
}
|
|
}
|