<?php

/**
 *  GoogleImages - Google Image Scraper
 *
 * Scrapes images off Google image search based on a specified query term.
 * 
 * @copyright  2008 The Dirty Frenchman
 * @license    http://www.gnu.org/licenses/gpl.html GNU General Public License
 * @version    0.1
 * @link       http://www.thedirtyfrenchman.com
 */

class GoogleImages
{    
     
/**
     * getImages : Returns an array containing a thumbnail link, fullsize image link
     * and ALT text link for specified keyword
     * 
     */
    
function getImages($keyword)
    {
        
$pics = array();

        
$searchURL 'http://images.google.com/images?svnum=10&um=1&hl=en&safe=off&q=';
        
$searchURL .= urlencode($keyword) . '&btnG=Search+Images"';
        
        
$results file_get_contents($searchURL);
        
        
preg_match_all('/dyn.Img.*?;/'$results$stringPREG_SET_ORDER );

        
$x=0;
        
        foreach(
$string as $img)
        {
            
$image explode(','str_replace("\"",'',$img[0]));
            
              
// Create array based on size
              
if (count($image)==16)
                    {
                            
$pics[$x][thumb] = $image[13] . '?q=tbn:' $image[2] . $image[3];
                            
$pics[$x][alt] = str_replace('...','',str_replace('\x3cb\x3e','',(str_replace('\x3c/b\x3e','',$image[6]))));
                            
$pics[$x][link] = $image[4];
                    }
              if (
count($image)==17)
                    {
                            
$pics[$x][thumb] = $image[14] . '?q=tbn:' $image[2] . $image[3];
                            
$pics[$x][alt] = str_replace('...','',str_replace('\x3cb\x3e','',(str_replace('\x3c/b\x3e','',$image[6]))));
                            
$pics[$x][link] = $image[3];
                    }
              if (
count($image)==18)
                    {
                            
$pics[$x][thumb] = $image[15] . '?q=tbn:' $image[2] . $image[3];
                            
$pics[$x][alt] = str_replace('...','',str_replace('\x3cb\x3e','',(str_replace('\x3c/b\x3e','',$image[6]))));
                            
$pics[$x][link] = $image[3];
                    }
                    
$x++;
        }
                
shuffle($pics);
                return 
$pics;
    }
}
?>