본문 바로가기
개발/aws

AWS Rekognition + PHP 이미지 분석

by 적아38 2021. 10. 8.
728x90

1. IAM  사용자  권한추가

   - AmazonRekognitionFullAccess

2. PHP용 AWS SDK 설치

   - https://aws.amazon.com/ko/sdk-for-php/

3. 코딩

<?php
require '/aws/aws-autoloader.php';
use Aws\Rekognition\RekognitionClient;

		$Client = new \Aws\Rekognition\RekognitionClient([
			'version' => 'latest',
			'region'  => 'ap-northeast-2',
			'credentials' => [
				'key'    => #{키값},
				'secret' => #{암호값}
			]
		]);
		
		$result = $Client->detectLabels([
			'Image' => [ 
				//1. URL및 이미지 사용시에 Bytes 사용
				//'Bytes' => file_get_contents("https://newsimg.hankookilbo.com/cms/articlerelease/2021/04/16/27f11979-f855-4628-8cad-c2ba207e3fee.png"),				
				//2. 버켓 사용
              	'S3Object'=>[
					'Bucket'=>#{Bucket}",
					'Name'=>#{디렉토리+파일명},
			 	]
			],
			'MaxLabels' => 10,
			'MinConfidence' => 90,
		]);
		print_r($result); // 확인
728x90

댓글