" to the script. // Example: "ua.php?i=0" would display the first image. // // If you want to hide the *.php extension and make it look // like a regular *.png image you can add a rewrite rule // in your Apache config. See an Apache rewrite example in my // forum topic (FORUM link at top of these comments). // // CREDITS: // I got and modified (with the Gimp) the ua.png image from here: // http://lwn.net/Gallery/page.php3?page=15 // I believe made by http://www.ftlinuxcourse.com/ // Ecsyle came up with the other images // // HISTORY: // Date Comment // -------- --------------------------------------------------------- // 2004-01-17 v0.3 - Added Tagline // 2004-01-16 v0.2.1 - Comment changes/additions // 2004-01-16 v0.2 - Added array of image attributes and randomized // 2004-01-12 v0.1 - Initial version hard coded with Tux image /////////////////////////////////////////////////////////////////////// error_reporting(0); // Log file $logfile = "/tmp/ua.log"; // Image directory in relation to ua.php script $imgdir = "ua"; // Image Array names $imgs = array("tuximg","tux2img","xmms","alsa"); // Image Arrays: name = PNG filename // numlines = number of text lines that will fit // xadd = text starts xadd pixels from the left // yadd = text starts yadd pixels from the top // xtag = tag starts xtag pixels from the left // ytag = tag starts xtag pixels from the left // gcr = Tagline color red component // gcg = Tagline color green component // gcb = Tagline color blue component // fcr = Foreground color red component // fcg = Foreground color green component // fcb = Foreground color blue component // bcr = Background color red component // bcg = Background color green component // bcb = Background color blue component // tcr = Transparent color red component // tcg = Transparent color green component // tcb = Transparent color blue component // Image #0 $tuximg = array("name"=>"tux.png","numlines"=>3, "xadd"=>145, "yadd"=>20, "xtag"=>160, "ytag"=>80, "gcr" =>0, "gcg" =>0, "gcb"=>0, "fcr" =>0xFE,"fcg" =>0xFE,"fcb"=>0xFE, "bcr" =>0, "bcg" =>0, "bcb"=>0, "tcr" =>246, "tcg" =>0, "tcb"=>255); // Image #1 $tux2img = array("name"=>"tux2.png","numlines"=>3, "xadd"=>145, "yadd"=>55, "xtag"=>170, "ytag"=>20, "gcr" =>0, "gcg" =>0, "gcb"=>0, "fcr" =>0x0,"fcg" =>0x0, "fcb"=>0x0, "bcr" =>0xFF,"bcg" =>0xFF,"bcb"=>0xFF, "tcr" =>246, "tcg" =>0, "tcb"=>255); // Image #2 $xmms = array("name"=>"xmms.png","numlines"=>2, "xadd"=>80, "yadd"=>31, "xtag"=>120,"ytag"=>79, "gcr" =>0, "gcg" =>0, "gcb"=>0, "fcr" =>0, "fcg" =>0, "fcb"=>0, "bcr" =>215,"bcg" =>219, "bcb"=>192, "tcr" =>246,"tcg" =>0, "tcb"=>255); // Image #3 $alsa = array("name"=>"alsa.png","numlines"=>2, "xadd"=>125,"yadd"=>36, "xtag"=>37, "ytag"=>108, "gcr" =>0, "gcg" =>0, "gcb"=>0, "fcr" =>255,"fcg" =>255, "fcb"=>255, "bcr" =>0, "bcg" =>0, "bcb"=>0, "tcr" =>246,"tcg" =>0, "tcb"=>255); // End of image configuration // End of user configuration // Count up how many images we have $numimgs = count($imgs); // If image not specifically selected or out of range // then pick one randomly if (! isset($i) || $i < 0 || $i >= $numimgs) { srand((double)microtime()*1000000); $i = rand(0,$numimgs-1); } // Get user agent string and IP address $ua = $_SERVER['HTTP_USER_AGENT']; $ip = $_SERVER['REMOTE_ADDR']; // Get hostname if it exists $fullhost = gethostbyaddr($ip); if ("$fullhost" == "$ip") { $isp = "unknown"; } else { $isp = preg_replace("/^[^.]+./", "", $fullhost); } // Check for crappy browser and OS if (preg_match("/compatible; MSIE/i","$ua") && ! preg_match("/Opera/","$ua")) { if (preg_match("/Windows/i","$ua")) { $brstr = "Your browser and your OS suck!"; } else { $brstr = "Your browser sucks but your OS is OK!"; } } else { if (preg_match("/Windows/i","$ua")) { $brstr = "Your browser is OK but your OS sucks!"; } else { $brstr = "Your browser and your OS are OK!"; } } // Send PNG Content-type header header("Content-type: image/png"); // Create an image using one of the array images as a base $uai = ImageCreateFromPNG("$imgdir/" . ${$imgs[$i]}[name]); // Set up foreground, background, and transparent colors $text_color = ImageColorAllocate($uai, ${$imgs[$i]}[fcr], ${$imgs[$i]}[fcg], ${$imgs[$i]}[fcb]); $background_color = ImageColorAllocate($uai, ${$imgs[$i]}[bcr], ${$imgs[$i]}[bcg], ${$imgs[$i]}[bcb]); $transcolor = ImageColorAllocate($uai, ${$imgs[$i]}[tcr], ${$imgs[$i]}[tcg], ${$imgs[$i]}[tcb]); $tag_color = ImageColorAllocate($uai, ${$imgs[$i]}[gcr], ${$imgs[$i]}[gcg], ${$imgs[$i]}[gcb]); // Set part of image transparent that matches transparent color ImageColorTransparent($uai, $transcolor); // Add tagline to image if (${$imgs[$i]}[numlines] > 0) { ImageString($uai,1,${$imgs[$i]}[xtag], ${$imgs[$i]}[ytag], "voidmain.is-a-geek.net", $tag_color); } // Add our text to the image if (${$imgs[$i]}[numlines] > 0) { ImageTTFtext($uai,8,0,${$imgs[$i]}[xadd], ${$imgs[$i]}[yadd], $text_color,"$imgdir/comic.ttf", "$brstr"); } if (${$imgs[$i]}[numlines] > 1) { ImageTTFtext($uai,8,0,${$imgs[$i]}[xadd], ${$imgs[$i]}[yadd]+15, $text_color,"$imgdir/comic.ttf", "Your IP address is $ip"); } if (${$imgs[$i]}[numlines] > 2) { ImageTTFtext($uai,8,0,${$imgs[$i]}[xadd], ${$imgs[$i]}[yadd]+30, $text_color,"$imgdir/comic.ttf", "Your ISP is $isp"); } // Pump that sucker out to the browser ImagePNG($uai); // Clean up ImageDestroy($uai); // If you don't want logging, comment the 4 lines below: $dt = date("Ymd G:i:s"); if (! $of = fopen($logfile,"a")) { exit; } fwrite($of,"$dt|1|$i|$ip|$HTTP_REFERER|$ua\n"); fclose($of); ?>