gpt4 book ai didi

image - Bing 图像搜索 API 按格式过滤

转载 作者:行者123 更新时间:2023-12-02 03:23:42 25 4
gpt4 key购买 nike

我正在使用此查询https://api.datamarket.azure.com/Bing/Search/v1/Image?Query=delhaize%20logo连接到 Bing 图像搜索 API 并查找所需的图像。这非常好用,但我喜欢 Bing 仅返回 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 中过滤它们即可。

关于image - Bing 图像搜索 API 按格式过滤,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31537676/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com