I’m developing a program whose background image will change in relation to the trending topics of twitter. So I have a function which returns me a word (first TT on twitter), then I need another function that will give me a url of an image relative to that word, like Google image search or flickr.
Do you know how to do this? or even better, do you have a php script made?
In summary: is there a function that will do a google image or flickr search, and return a corresponding url to an image for the word
Google’s AJAX Search API allows you to search for images: Video and Image Search Examples, though whether you could use PHP to parse the results I’m not sure. You could certainly parse the returned data to extract image urls to apply as backgrounds though. There is also a Yahoo Image Search API and flickr Search API to try.
The Google AJAX Documentation has a PHP code snippet that shows how to call searches using PHP.
Here’s code that finds image search results for “batman”:
Here’s what the raw returned json looks like when decoded:
A tricky aspect of this is that you may need permission to use these images. In some testing it looks like when you restrict by public domain you get far fewer images in result. Also, there’s no mechanism to restrict to servers that are actually available at that time, so sometimes you may get a valid url but no image will be available. It seems like a simple request, but it introduces other issues in url handling.