78 lines
1.7 KiB
PHP
78 lines
1.7 KiB
PHP
<?php
|
|
|
|
/**
|
|
* @package: events-venues-task
|
|
* @author: Yevhen Odynets
|
|
* @date: 2024-07-27
|
|
* @time: 07:35
|
|
*/
|
|
|
|
//phpcs:ignore
|
|
declare(strict_types = 1);
|
|
|
|
namespace App\Services\Image;
|
|
|
|
use App\ConsoleStyleInterfaceType;
|
|
use App\LoggingSeverityLevelsType;
|
|
use App\Services\Image\Contracts\ImageInterface;
|
|
use App\Services\Image\ImageCropperTrait as Cropper;
|
|
use Exception;
|
|
use Illuminate\Support\Facades\{App, Log, Storage};
|
|
use Symfony\Component\Console\{Input\ArgvInput, Output\ConsoleOutput, Style\SymfonyStyle};
|
|
|
|
final class Image implements ImageInterface
|
|
{
|
|
use Cropper;
|
|
|
|
public static mixed $faker = null;
|
|
private SymfonyStyle $io;
|
|
private array $config;
|
|
private bool $isConsole;
|
|
private bool $isVerbosity;
|
|
private bool $isIO;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->config = config('image');
|
|
}
|
|
|
|
/**
|
|
* @param string $imagePath
|
|
*
|
|
* @return string|null
|
|
*/
|
|
public function localPath(string $imagePath): ?string
|
|
{
|
|
$fullPath = realpath(Storage::path($imagePath));
|
|
|
|
if (! $fullPath || ! file_exists($fullPath)) {
|
|
return null;
|
|
}
|
|
|
|
return $fullPath;
|
|
}
|
|
|
|
/**
|
|
* @param string $fullPath
|
|
* @param string|null $property
|
|
*
|
|
* @return array|string
|
|
*/
|
|
public function meta(string $fullPath, ?string $property = null): array|string
|
|
{
|
|
try {
|
|
$meta = getimagesize($fullPath);
|
|
|
|
if (is_null($property) === false && array_key_exists($property, $this->config['meta'])) {
|
|
return $meta[$this->config['meta'][$property]];
|
|
}
|
|
|
|
return getimagesize($fullPath);
|
|
} catch (Exception $e) {
|
|
appWarning($e);
|
|
}
|
|
|
|
return [];
|
|
}
|
|
}
|