Steve Scrimpshire Posted February 11, 2005 Report Share Posted February 11, 2005 (edited) Someone asked me about this, so I thought I would post it here also in case others are interested. I've included an image of my signature in this post in case I change my signature one day. You need php-gd installed on the server that runs this script. Here's the script, which I named stats.png: <?php /* Copyright 2005 Steve Scrimpshire This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ Header ("Content-type: image/png"); Header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); Header("Expires: Thu, 19 Nov 1981 08:52:00 GMT"); Header("Pragma: no-cache"); $img = @ImageCreateFromPNG("setibg.png"); $stats = file('setistats.txt'); function file_trim(&$value, $key) { $value = trim($value); } @array_walk($stats, 'file_trim'); $font = '/home/omar/.fonts/quillscriptnormal.ttf'; $bg = ImageColorAllocate($img, 0, 0, 0); $cputime = str_replace("Total CPU Time ", "CPU Time", "$stats[7]"); $timeperunit = str_replace("Average CPU Time per work unit ", "CPU Time per unit", "$stats[8]"); $wuperday = str_replace("Average results received per day", "Units/day ", "$stats[9]"); $text_color = ImageColorAllocate ($img, 255, 255, 255); $title_color = ImageColorAllocate ($img, 0, 0, 205); ImageTTFtext($img, 11, 0, 23, 33, $text_color, $font, "$cputime"); ImageTTFtext($img, 11, 0, 23, 45, $text_color, $font, "$timeperunit"); ImageTTFtext($img, 11, 0, 23, 57, $text_color, $font, "$wuperday"); ImagePNG($img); ImageDestroy($img); ?> setibg.png resides in the same directory as the php script and is my background image. Pay attention to the font path; yours will be different. Then I needed something to grab my stats. I could've grabbed the stats in the script, but then the seti page would get spammed every time someone viewed my image which is a bad idea . I created this script: #!/bin/bash lynx -dump "http://setiathome2.ssl.berkeley.edu/fcgi-bin/fcgi?email=omarserenity@yahoo.com&cmd=user_stats_new" > /var/www/html/setistats.txt I called it setistats and put it in /usr/bin, making it executable with chmod +x /usr/bin/setistats. Then I made a cron job that runs as root, calling this script once a day. My cronjob runs on the same box that I run apache on, where the stats.png runs, too, so if your stats.png runs on a remote server, you can run your cron job on your local box and just change /var/www/html/setistats.txt to ~/setistats.txt Then add a line below that uploads it to your remote server, something like: ncftpput -u username -p password <<remote-host>> <<remote-directory>> ~/setistats.txt not actually using the <<>> but substituting the info needed there. Then on the server the stats.png runs on, you need an .htaccess file to tell it to run stats.png as a php script like this: <Files stats.png> ForceType application/x-httpd-php </Files> make it your sig by using [img=http://yourserver.com/stats.png] Feel free to use my background image and consider it released under the GNU GPL license as well. gpl.txt Edited February 24, 2005 by Steve Scrimpshire Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted March 5, 2005 Author Report Share Posted March 5, 2005 (edited) Due to the recent problems with the SetiAtHome servers, I have revised my script, possibly only temporarily. I'm not very good at comprehending all the stuff in the *.sah files in my seti directory, so I use PerlSeti for this. I keep perlseti running, so it keeps updating perlseti-stats.html when needed. I changed my /usr/bin/setistats, that the cron job runs, to look like this: #!/bin/bash cp --force /home/omar/seti/perlseti-stats.html /var/www/html lynx -dump "http://192.168.1.101/perlseti-stats.html" > /var/www/html/setistats.txt 192.168.1.101 is the ip of my server that seti and this script run on. Then, since I'm parsing entirely different info, I changed my signature script to look like this: <?php $img = @ImageCreateFromPNG("setibg.png"); $stats = file('setistats.txt'); function file_trim(&$value, $key) { $value = trim($value); } @array_walk($stats, 'file_trim'); $font = '/home/omar/.fonts/quillscriptnormal.ttf'; $bg = ImageColorAllocate($img, 0, 0, 0); $units_received = str_replace("Units Received : ", "", "$stats[3]"); $units_returned = "$stats[4]"; $cputime = str_replace("CPU time", "CPU Time ", "$stats[5]"); $text_color = ImageColorAllocate ($img, 255, 255, 255); if ( $units_received == "0" ) { $working = "Waiting for new work unit..."; ImageTTFtext($img, 11, 0, 76, 56, $text_color, $font, "$working"); } elseif ( $units_received == "1" ) { $working = "Working on 1 unit..."; ImageTTFtext($img, 11, 0, 103, 56, $text_color, $font, "$working"); } else { $working = "Working on $units_received units..."; ImageTTFtext($img, 11, 0, 103, 56, $text_color, $font, "$working"); } //ImageTTFtext($img, 11, 0, 63, 32, $text_color, $font, "$working"); ImageTTFtext($img, 11, 0, 48, 44, $text_color, $font, "$units_returned"); ImageTTFtext($img, 11, 0, 48, 32, $text_color, $font, "$cputime"); Header ("Content-type: image/png"); Header("Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0"); Header("Expires: Thu, 19 Nov 1981 08:52:00 GMT"); Header("Pragma: no-cache"); ImagePNG($img); ImageDestroy($img); ?> Attached is an updated example signature: Edited March 5, 2005 by Steve Scrimpshire Quote Link to comment Share on other sites More sharing options...
Steve Scrimpshire Posted March 18, 2005 Author Report Share Posted March 18, 2005 As you may notice, my sig is back to the way it was with the original script. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.