feat: add fullscreen viewer

This commit is contained in:
2025-08-08 00:25:27 +03:00
parent d9fd26d354
commit 4ae8d59328
11 changed files with 271 additions and 147 deletions

View File

@@ -56,4 +56,22 @@ class ImageTool implements ImageToolInterface
return rtrim($this->siteUrl, '/') . '/image/' . str_replace($this->imageDir, '', $fullNewPath);
}
public function getUrl(string $path): string
{
return rtrim($this->siteUrl, '/') . '/image/' . str_replace($this->imageDir, '', $path);
}
public function getRealSize(string $path): array
{
$fullPath = $this->imageDir . $path;
if (! is_file($fullPath)) {
throw new \RuntimeException('Image file not found: ' . $path);
}
$img = $this->manager->make($fullPath);
return [$img->getWidth(), $img->getHeight()];
}
}

View File

@@ -4,6 +4,9 @@ namespace Openguru\OpenCartFramework\ImageTool;
interface ImageToolInterface
{
public function getUrl(string $path): string;
public function getRealSize(string $path): array;
public function resize(
string $path,
int $width,

View File

@@ -230,20 +230,20 @@ class ProductsHandler
->where('products_images.product_id', '=', $productId)
->get();
$images = [];
$images[] = [
'url' => $this->ocImageTool->resize(
$product['product_image'],
$imageWidth,
$imageHeight,
'placeholder.png'
),
'alt' => $product['product_name'],
];
$imagePaths = [];
$imagePaths[] = $product['product_image'];
foreach ($productsImages as $item) {
$imagePaths[] = $item['image'];
}
$images = [];
foreach ($imagePaths as $imagePath) {
[$width, $height] = $this->ocImageTool->getRealSize($imagePath);
$images[] = [
'url' => $this->ocImageTool->resize($item['image'], $imageWidth, $imageHeight, 'placeholder.png'),
'thumbnailURL' => $this->ocImageTool->resize($imagePath, $imageWidth, $imageHeight, 'placeholder.png'),
'largeURL' => $this->ocImageTool->getUrl($imagePath),
'width' => $width,
'height' => $height,
'alt' => $product['product_name'],
];
}