first commit

This commit is contained in:
ExtraNetwork
2026-05-12 17:04:54 +03:00
commit e5c4b6aa13
1425 changed files with 284735 additions and 0 deletions

View File

@@ -0,0 +1,72 @@
<?php
namespace App\Core\Service\Google;
use App\Exceptions\ApiErrorException;
use Exception;
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
use Illuminate\Support\Facades\Log;
class GoogleVisionLabelService
{
private $googleVisionAuthentication ;
public function __construct()
{
$this->googleVisionAuthentication = base_path().'/resources/data/google-vision-authentication.json';
putenv('GOOGLE_APPLICATION_CREDENTIALS='.$this->googleVisionAuthentication );
}
public function getImageGoogleVisionLabels($params)
{
$photoLabelList = [];
try
{
$imagePath = $params['image_paths'];
$image = file_get_contents($imagePath);
$imageAnnotator = new ImageAnnotatorClient();
$responseImageAnnotator = $imageAnnotator->labelDetection($image);
$getLabelAnnotations = $responseImageAnnotator->getLabelAnnotations();
$getLabelAnnotations = $getLabelAnnotations ? $getLabelAnnotations : null;
if( empty($getLabelAnnotations) )
{
throw new ApiErrorException(lang('Not tags found!'));
}
if ($getLabelAnnotations) {
$i = 1;
foreach ($getLabelAnnotations as $labelAnnotation)
{
$photoLabelList[] =
[
'description' => $labelAnnotation->getDescription(),
'score' => $labelAnnotation->getScore(),
'topicality' => $labelAnnotation->getTopicality(),
];
if($i == 3){
break;
}
$i++;
}
Log:info($photoLabelList);
}
$imageAnnotator->close();
}catch (Exception $e)
{
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
Log::error($message);
}
return $photoLabelList;
}
}