src/Philip/Plugin/ImageMePlugin.php
public function getImage($term, $gif = false) {
        $term = urlencode($term);
        $url = "http://ajax.googleapis.com/ajax/services/search/images?q={$term}&v=1.0&rsz=8&safe=active";

        if ($gif) {
            $url .= "&as_filetype=gif";
        }

        $json = trim(file_get_contents($url));
        $decoded = json_decode($json, true);
        $results = isset($decoded['responseData']['results']) ? $decoded['responseData']['results'] : array();

        if (!empty($results)) {
            $result = $results[array_rand($results)];
            return $result['unescapedUrl'];
        }
    }
public function getImage($term, $gif = false) {
        $term = urlencode($term);
        $url = "http://ajax.googleapis.com/ajax/services/search/images?q={$term}&v=1.0&rsz=8&safe=active";

        if ($gif) {
            $url .= "&as_filetype=gif";
        }

        $json = trim(file_get_contents($url));
        $decoded = json_decode($json, true);
        $results = isset($decoded['responseData']['results']) ? $decoded['responseData']['results'] : array();

        if (!empty($results)) {
            $result = $results[array_rand($results)];
            return $result['unescapedUrl'];
        }
    }
Uses the (deprecated) Google Images API to locate a random image

@param string  $term The term to search for
@param boolean $gif  True if you only want to search for gifs

@return mixed The URL of a found image, null otherwise