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; } }