Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
AWS Rekognition PHP SDK提供无效的图像编码错误_Php_Amazon Web Services_Amazon Rekognition - Fatal编程技术网

AWS Rekognition PHP SDK提供无效的图像编码错误

AWS Rekognition PHP SDK提供无效的图像编码错误,php,amazon-web-services,amazon-rekognition,Php,Amazon Web Services,Amazon Rekognition,我正在使用PHPSDK上传一个本地文件(不是S3),以便在AWS Rekognion中进行解析。但是,图像blob将不起作用,我收到消息:InvalidImageFormatException:“无效图像编码” 我尝试了多个图像(),但都不起作用 我的代码是: $client = new RekognitionClient($credentials); $im = file_get_contents('/app/image1.png'); $imdata = base64_encode($im

我正在使用PHPSDK上传一个本地文件(不是S3),以便在AWS Rekognion中进行解析。但是,图像blob将不起作用,我收到消息:
InvalidImageFormatException:“无效图像编码”

我尝试了多个图像(),但都不起作用

我的代码是:

$client = new RekognitionClient($credentials);

$im = file_get_contents('/app/image1.png');
$imdata = base64_encode($im);

$result = $client->detectLabels(
    [
       'Image' => [
          'Bytes' => $imdata,
       ]
    ]
);
我的编码正确吗?答案很模糊

我发现了很多关于“无图像内容”的问题,但没有关于无效格式的问题

有什么想法吗?谢谢

我最终使用了而不是
base64\u编码
路由。我怀疑这不是最好的方法,但它确实非常有效

$client = new RekognitionClient($credentials);

$image = new Imagick('/app/image1.png');
$imdata = $image->getImageBlob();

$result = $client->detectLabels(
    [
       'Image' => [
          'Bytes' => $imdata,
       ]
    ]
);

看起来您不应该应用base64编码。SDK为BLOB做这件事

:

使用SDK时,您不需要以64_编码映像

如果您使用的是AWS SDK,则代码可能不需要对图像字节进行编码


检查base64_encode()是否未返回FALSE。另外,请尝试旧式数组:detectLabels(array('Image'=>array('Bytes'=>imdata))@SergeyKovalev Yep,
base64\u encode()
确实按预期返回了数据,不幸的是,更改数组样式也不起作用:/如果跳过
base64\u encode()
部分怎么办?您不应该使用base64\u encode()。如果没有它,它就可以工作。@nibty那么我应该向请求传递什么呢?除了一个Imagick blob之外,什么都不起作用?我一直无法让它起作用,它给了我同样的错误…看起来文档很混乱。他们应该说“你不能”而不是“可能不需要”。你不需要任何图书馆来做到这一点。这与调用
file\u get\u contents('/app/image1.png')
完全相同。
        case 'blob':
            return base64_encode($value);
    $s3 = new \Aws\Rekognition\RekognitionClient([
        'version' => 'latest',
        'region'  => 'us-east-1',
        'credentials' => [
            'key'    => 'BKxxxxxxxx',
            'secret' => 'GYxxxxxxxxxxxxxxxxxx'
        ]
    ]);

    $result = $s3->detectLabels([
        'Image' => [ // REQUIRED
            'Bytes' => file_get_contents("http://img13.deviantart.net/5a3b/i/2010/249/b/a/__michelangelo__s_flying_horse___by_dark_oak_trails-d2y5iej.jpg"),
        ],
        'MaxLabels' => 10,
        'MinConfidence' => 90,
    ]);