composed project, added packages, models, controllers, seeders, mirgations etc.
This commit is contained in:
77
app/Services/Image/Image.php
Normal file
77
app/Services/Image/Image.php
Normal file
@@ -0,0 +1,77 @@
|
||||
<?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 [];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user