Hobo Script I - Using PHP to display LiveJournal user images based on referring URL, and modifying resulting image  
      By Brendan CM <verifex (a t) g m a i l (0) com>  
  Here is a little PHP script I wrote to pull the referring URL from a page, parse the possible LiveJournal username from the URL, then connect to LiveJournal and parse the user images page so I have a array of user images to play with. Pick a random one, put some text over it, and Viola!  
  //      Go to MaxMind.com to get these spiffy country-ip PHP functions.
  $gi = geoip_open("\GeoIP.dat",GEOIP_STANDARD);
  $comefrom=$_SERVER['HTTP_REFERER'];  // the referring URL
  //      Regular expression to check referring URL to see if it has livejournal username in it.
  //      Regular expression to check userpic page on livejournal to grab all the user image urls.
  $pattern2="|<img src=\'http:\/\/www\.livejournal\.com\/userpic\/([0-9]+)\/([0-9]+)\'|U";

  //      If this person isn't from Livejournal, grab the domain name if it has www in it

  //      PHP regular expression functions, pass found data into array $users and $users2
  //      cordinates of picture, and resized cordinates of userpic grabbed.
  $thex=200; $they=200; $thumbx=200; $thumby=200;
  //      Actual picture that will be served to browser
  $im = imagecreatetruecolor ($thex, $they) or die ("Cannot Initialize new GD image stream");
  //      The text strings to add onto the image
  $textx="WELCOME"; $textz="FAN";
  //      Lets make sure my random numbers are really random
  function make_seed()
    list($usec, $sec) = explode(' ', microtime());
    return (float) $sec + ((float) $usec * 100000);

  if ($users[1][0]!="") {

    //      I'm using a custom http access class, but you can use snoopy http://snoopy.sourceforge.net/
    $client = new HttpClient('www.livejournal.com');
    $client->timeout = 20;
    $client->max_redirects = 50;
    $client->cookie_host = 'www.livejournal.com';
    $client->setUserAgent('Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.3a) Gecko/20021207');
    $picss = $client->getContent();

    //     Pull out image urls from page content
    if (!$im) { die("ERROR"); }
    //     Pick a number between the first and last of available user images on LJ
    //     Generate the URL of the user image based on the data parsed from the page
    //     Pull image data so we can check what it is and how big it is
    list($width, $height, $type, $attr) = getimagesize($picurl);
    //     Check which image type it is, and use appropriate function to create the new image
    switch ($type) {
    	case 1:	$imgar = @imagecreatefromgif($picurl);
    	case 2: $imgar = @imagecreatefromjpeg($picurl);
	    case 3: $imgar = @imagecreatefrompng($picurl);
    	case 6: $imgar = @imagecreatefromwbmp($picurl);
    //     If image was created, resize image to take up full size of image you are creating
    if (isset($imgar)) {
      imagecopyresized($im, $imgar, 0, 0, 0, 0, $thumbx, $thumby, $width, $height);

    //     Making username uppercase, for extra pizazz!
  } elseif ($users2[1][0]!="") {
    //     If LJ user wasn't found, just spout domain name.
  } else {
    //     Looks like they didn't give me a referring URL, or they had some funky url
  //      This function displays the country name per IP
  $textw="You from ".geoip_country_name_by_addr($gi, $_SERVER["REMOTE_ADDR"])."?";
  //      I'm using this font for everything
  imagettftext($im, 10, 0, 24, 182, $blue, $font, $textw);
  imagettftext($im, 15, 0, 44, 61, $red, $font, $textx);
  imagettftext($im, 15, 0, 15, 100, $green, $font, $texty);
  imagettftext($im, 15, 0, 80, 142, $purple, $font, $textz);
  //      Display header or else browser will get cranky!
  header("Content-type: image/jpeg");
  //      Finally display the darned picture!
Creative Commons: Some Rights Reserved Valid HTML 4.01! Valid CSS!