I'm using this query https://api.datamarket.azure.com/Bing/Search/v1/Image?Query=delhaize%20logo to connect to the Bing Image Search API and find the desired image. This works very good, but I like Bing to return only jpg and png images. I cannot find anywhere how to filter on image format with Bing.
I found this page regarding image filters but it doesn't mention image format anywhere.
Any ideas?
Nope, there is no method to filter by image format. You could do this though (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);
This will find images that match the "monitor" string, and then you just filter them in php.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With