必应图像搜索API按格式过滤

3
我正在使用此查询https://api.datamarket.azure.com/Bing/Search/v1/Image?Query=delhaize%20logo连接到必应图像搜索API并查找所需的图像。这很有效,但我希望Bing仅返回jpg和png图像。我无法在任何地方找到如何使用Bing筛选图像格式的信息。
我发现this页面有关于图像过滤器的内容,但没有提及图像格式。
有什么想法吗?
1个回答

1

没有方法可以按图像格式进行过滤。不过您可以通过以下方式实现(php):

$word = 'monitor';
$extension = 'jpg';

$request = 'https://api.datamarket.azure.com/Bing/Search/v1/Image?$format=json&Query=%27'.urlencode($word).'%27&Adult=%27Strict%27&ImageFilters=%27Size%3AMedium%2BAspect%3AWide%2BColor%3AColor%2BStyle%3APhoto%27';
$process = curl_init($request);
curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($process, CURLOPT_USERPWD,  "$accountKey:$accountKey");
curl_setopt($process, CURLOPT_TIMEOUT, 30);
curl_setopt($process, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($process);
$json = json_decode($response, true);

if(is_array($json['d']['results'])) {
    foreach($json['d']['results'] as $image) {
        if(pathinfo($image['MediaUrl'], PATHINFO_EXTENSION) == $extension) {
            # update values
            $urls[] = $image['MediaUrl'];
        }
    }
}

print_r($urls);

这将查找与“monitor”字符串匹配的图像,然后您只需在php中过滤它们。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接