Bing 图片搜索 API 按格式过滤
Bing Image Search API filter by format
我正在使用此查询 https://api.datamarket.azure.com/Bing/Search/v1/Image?Query=delhaize%20logo 连接到 Bing 图片搜索 API 并找到所需的图片。这很好用,但我只喜欢 Bing 到 return jpg 和 png 图像。我无法在任何地方找到如何使用 Bing.
过滤图像格式
我找到了 this 关于图像过滤器的页面,但它没有在任何地方提到图像格式。
有什么想法吗?
不,没有按图像格式过滤的方法。你可以这样做 (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 中过滤它们。
我正在使用此查询 https://api.datamarket.azure.com/Bing/Search/v1/Image?Query=delhaize%20logo 连接到 Bing 图片搜索 API 并找到所需的图片。这很好用,但我只喜欢 Bing 到 return jpg 和 png 图像。我无法在任何地方找到如何使用 Bing.
过滤图像格式我找到了 this 关于图像过滤器的页面,但它没有在任何地方提到图像格式。
有什么想法吗?
不,没有按图像格式过滤的方法。你可以这样做 (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 中过滤它们。