【发布时间】:2017-06-22 15:51:50
【问题描述】:
我正在使用 PHP 开发工具包上传要在 AWS Rekognition 中解析的本地文件(不是 S3)。但是,图像 blob 不起作用,我收到消息:InvalidImageFormatException: "Invalid image encoding"。
我尝试了多张图片 (the docs say JPEGs and PNGs are accepted),但都没有效果。
我的代码是:
$client = new RekognitionClient($credentials);
$im = file_get_contents('/app/image1.png');
$imdata = base64_encode($im);
$result = $client->detectLabels(
[
'Image' => [
'Bytes' => $imdata,
]
]
);
我的编码是否正确? docs 相当模糊。
我发现了一些关于“无图像内容”的问题,但没有发现关于无效格式的问题。
有什么想法吗?谢谢!
【问题讨论】:
-
检查 base64_encode() 是否返回 FALSE。另外,尝试旧式数组:detectLabels(array('Image'=>array('Bytes'=>$imdata)))
-
@SergeyKovalev 是的,
base64_encode()确实按预期返回了数据,不幸的是,更改数组样式也不起作用:/ -
如果你跳过
base64_encode()部分怎么办? -
你不应该使用 base64_encode()。没有它也可以工作。
-
@nibty 那我要传递给请求什么?除了 Imagick 的 blob 之外,没有什么可以用?
标签: php amazon-web-services amazon-rekognition