feat: add fullscreen viewer
This commit is contained in:
@@ -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()];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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,
|
||||
|
||||
0
module/oc_telegram_shop/upload/oc_telegram_shop/src/Exceptions/CustomExceptionHandler.php
Normal file → Executable file
0
module/oc_telegram_shop/upload/oc_telegram_shop/src/Exceptions/CustomExceptionHandler.php
Normal file → Executable 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'],
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user