Google's AJAX Search API 이미지를 검색 할 수 있습니다. Video and Image Search Examples, PHP를 사용하여 확실하지 않은 결과를 구문 분석 할 수 있는지 여부. 반환 된 데이터를 구문 분석하여 배경으로 적용 할 이미지 URL을 추출 할 수 있습니다. 시도 할 Yahoo Image Search API 및 flickr Search API도 있습니다.
Google AJAX Documentation에는 PHP를 사용하여 검색을 호출하는 방법을 보여주는 PHP code snippet이 있습니다.
Array
(
[responseData] => Array
(
[results] => Array
(
[0] => Array
(
[GsearchResultClass] => GimageSearch
[width] => 240
[height] => 338
[imageId] => k8FYqFKsdhvu3M:
[tbWidth] => 84
[tbHeight] => 119
[unescapedUrl] => http://lizilla.files.wordpress.com/2009/08/batman.jpg
[url] => http://lizilla.files.wordpress.com/2009/08/batman.jpg
[visibleUrl] => lizilla.wordpress.com
[title] => Superhero's, Animation, Comics, And Interesting Movies. « Lizilla
[titleNoFormatting] => Superhero's, Animation, Comics, And Interesting Movies. « Lizilla
[originalContextUrl] => http://lizilla.wordpress.com/2009/08/26/superheros-animation-comics-and-interesting-movies/
[content] => Dunanununanuna <b>BATMAN</b>!
[contentNoFormatting] => Dunanununanuna BATMAN!
[tbUrl] => http://images.google.com/images?q=tbn:k8FYqFKsdhvu3M::lizilla.files.wordpress.com/2009/08/batman.jpg
)
[1] => Array
(
[GsearchResultClass] => GimageSearch
[width] => 307
[height] => 290
[imageId] => faxJ90Dbo1TW1M:
[tbWidth] => 117
[tbHeight] => 111
[unescapedUrl] => http://www.solarnavigator.net/films_movies_actors/film_images/batman_michael_keaton_jack_nocholson_joker_marvel_comics.jpg
[url] => http://www.solarnavigator.net/films_movies_actors/film_images/batman_michael_keaton_jack_nocholson_joker_marvel_comics.jpg
[visibleUrl] => www.solarnavigator.net
[title] => <b>BATMAN</b> THE MOVIE
[titleNoFormatting] => BATMAN THE MOVIE
[originalContextUrl] => http://www.solarnavigator.net/films_movies_actors/batman.htm
[content] => <b>Batman</b> and the Joker in the
[contentNoFormatting] => Batman and the Joker in the
[tbUrl] => http://images.google.com/images?q=tbn:faxJ90Dbo1TW1M::www.solarnavigator.net/films_movies_actors/film_images/batman_michael_keaton_jack_nocholson_joker_marvel_comics.jpg
)
[2] => Array
(
[GsearchResultClass] => GimageSearch
[width] => 300
[height] => 300
[imageId] => nDWzhPnraNi_gM:
[tbWidth] => 116
[tbHeight] => 116
[unescapedUrl] => http://i192.photobucket.com/albums/z167/Great_WhiteSnark/batman_bale-1.jpg
[url] => http://i192.photobucket.com/albums/z167/Great_WhiteSnark/batman_bale-1.jpg
[visibleUrl] => www.coolchaser.com
[title] => <b>batman</b> MySpace graphics and comments
[titleNoFormatting] => batman MySpace graphics and comments
[originalContextUrl] => http://www.coolchaser.com/graphics/tag/batman
[content] => All Graphics » <b>batman</b>
[contentNoFormatting] => All Graphics » batman
[tbUrl] => http://images.google.com/images?q=tbn:nDWzhPnraNi_gM::i192.photobucket.com/albums/z167/Great_WhiteSnark/batman_bale-1.jpg
)
[3] => Array
(
[GsearchResultClass] => GimageSearch
[width] => 250
[height] => 302
[imageId] => W9EAV1DUDesHuM:
[tbWidth] => 96
[tbHeight] => 116
[unescapedUrl] => http://upload.wikimedia.org/wikipedia/en/thumb/f/f6/New_Batman_Adventures_cast.jpg/250px-New_Batman_Adventures_cast.jpg
[url] => http://upload.wikimedia.org/wikipedia/en/thumb/f/f6/New_Batman_Adventures_cast.jpg/250px-New_Batman_Adventures_cast.jpg
[visibleUrl] => en.wikipedia.org
[title] => The New <b>Batman</b> Adventures - Wikipedia, the free encyclopedia
[titleNoFormatting] => The New Batman Adventures - Wikipedia, the free encyclopedia
[originalContextUrl] => http://en.wikipedia.org/wiki/The_New_Batman_Adventures
[content] => The New <b>Batman</b> Adventures
[contentNoFormatting] => The New Batman Adventures
[tbUrl] => http://images.google.com/images?q=tbn:W9EAV1DUDesHuM::upload.wikimedia.org/wikipedia/en/thumb/f/f6/New_Batman_Adventures_cast.jpg/250px-New_Batman_Adventures_cast.jpg
)
)
[cursor] => Array
(
[pages] => Array
(
[0] => Array
(
[start] => 0
[label] => 1
)
[1] => Array
(
[start] => 4
[label] => 2
)
[2] => Array
(
[start] => 8
[label] => 3
)
[3] => Array
(
[start] => 12
[label] => 4
)
[4] => Array
(
[start] => 16
[label] => 5
)
[5] => Array
(
[start] => 20
[label] => 6
)
[6] => Array
(
[start] => 24
[label] => 7
)
[7] => Array
(
[start] => 28
[label] => 8
)
)
[estimatedResultCount] => 3050000
[currentPageIndex] => 0
[moreResultsUrl] => http://www.google.com/images?oe=utf8&ie=utf8&source=uds&start=0&safe=active&imgsz=medium&as_filetype=jpg&hl=en&q=batman
)
)
[responseDetails] =>
[responseStatus] => 200
)
이의 까다로운 측면은 당신이 할 수 있다는 것이다 :
여기
$word = "batman";
$manual_referer = 'http://example.com/';
// See reference for how to modify search
// http://code.google.com/apis/ajaxsearch/documentation/reference.html
$args = array(
'v' => '1.0',
'q' => $word,
'as_filetype' => 'jpg',
'imgsz' => 'medium', // image size
'safe' => 'active', // image "safeness"
'as_filetype' => 'jpg',
);
$url = "http://ajax.googleapis.com/ajax/services/search/images?";
foreach ($args as $key => $val) {
$url .= $key . '=' . rawurlencode($val) . '&';
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_REFERER, $manual_referer);
$body = curl_exec($ch);
curl_close($ch);
$json = json_decode($body, true);
$results = $json['responseData']['results'];
foreach ($results as $result) {
print "<img src=";
print $result['url']; // here's your url
print ">";
}
원시은 JSON 디코딩 할 때 보이는 반환 내용은 다음과 같습니다 여기
은 "배트맨"에 대한 이미지 검색 결과를 찾아 코드의 이 이미지를 사용할 권한이 필요합니다. 일부 테스트에서는 공개 도메인을 제한하면 결과에서 훨씬 적은 수의 이미지를 얻는 것처럼 보입니다. 또한 실제로 사용할 수있는 서버로 제한 할 수있는 메커니즘이 없기 때문에 유효한 URL을 얻을 수 있지만 이미지를 사용할 수없는 경우도 있습니다. 간단한 요청처럼 보이지만 URL 처리에 다른 문제가 있습니다.
결과에 놀랄 준비를하십시오. – zneak
오해의 소지가있는 사람들을 위해 : 그는 구글 이미지 나 플리커 검색을 할 수있는 기능을 원하고 그가 가지고있는 단어의 이미지에 대응하는 URL을 준다. –
@zneak : 재미있다! 확실하게 Google 이미지 검색은 '안전한'것으로 판단되는 이미지를 필터링하는 매개 변수를 제공합니다. 분명히 보장 할 수는 없지만 뭔가 있습니다. :-) – artlung