我一直试图从API检索屏幕截图,但是当我解码图像并将其保存时,会得到损坏的图像。下面是我正在使用的代码。我创建了一个指向包含google响应的示例文件的tinyurl,如果您想对其进行测试。
$name = 'test';
$result = file_get_contents('http://tinyurl.com/q4smyod');
$result = json_decode($result, true);
$decoded=base64_decode($result['screenshot']['data']);
file_put_contents('img/'.$name.'.jpg',$decoded);
如我的评论中所述,问题是由使用php API时Google加密错误引起的。如果遇到此问题,只需使用以下替换功能即可修复编码。
$data = str_replace('_','/',$result['screenshot']['data']);
$data = str_replace('-','+',$data);
$decoded = base64_decode($data);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句