tomclegg.net


Diary
Examples
    256-router
    adzap
    apache-double-reverse
    cacti-adodb-php4
    debian-quota
    diskonmodule
    dollarsperbyte
    dynip
    ezmlm-linux
    fbsdhabits
    freebsdclone
    macbook-quantal-sound
    maildirpop3d-awfulhak
    mandy
    md
    mrtg
    net-snmp
    nodefaultroute
    oracle9i
    oracle9i-bsd5
    oracle9i-client
    oracle9i-nat
    php-cgi
    php-commandline
  >php-image<
    php-kics
    php-mini_httpd
    pinouts
    pizzaperdollar
    plesk-symlink-php
    pxe
    qmail-linux
    qmail-qfilter
    racoon-sonicwall
    redundant-vpn
    rewriterule
    seahorse-workaround
    setting-locale-failed
    smalldog
    snmpv3-cacti
    spamassassin
    squid-tproxy
    supfile
    suse73
    svc-nmbd
    svc-smbd
    svc-smtpd
    switch-virtualbox-virsh
    toyotastereo
    vm
    vn-file
    wmp-invalid
    xcode-remote-install
    xen-eth0-renamed
    xen-monowall
    xen3-ubuntu-dapper
    zz-update-grub-fail
Hire Tom
Mostly Mozart
Patches
School
Scrapbook
Software
Telephones




colocation
comments
davidireland
edsgranola
faq
funsites
goodlooking
goodmovies
google-earth-saucy-amd64
houserules
liberating
resume
resume2
scratch
shopping
snacks
todo
university
warisbogus

Create a PNG image with PHP
Posted May 4, 2003
# Compile PHP with bundled GD library:

cd /tmp
tar xyf /usr/local/src/php-4.3.1.tar.bz2
cd php-4.3.1
'./configure' '--with-gd' '--with-mysql=/usr/local' \
 '--with-mhash=/usr/local' '--with-mcrypt=/usr/local' \
 '--enable-sockets' '--enable-trans-sid' '--prefix=/usr/local' \
 '--with-readline=/usr' '--with-regex=system' '--with-zlib' \
 '--enable-force-cgi-redirect' '--enable-track-vars' \
 '--with-gettext'
make
cp sapi/cgi/php ~/public_html/php.cgi

# Sample PHP code:

<?

$w = 600;
$h = 400;

$i = imagecreate($w,$h);
$bg = imagecolorallocate ($i, 0x2B, 0x43, 0x71);
$fg = imagecolorallocate ($i, 0xFF, 0xFF, 0xFF);
$sc = imagecolorallocate ($i, 0xFF, 0xFF, 0x00);
imagestring ($i, 1, 30, $h-30,  "Link integrity: number of ping packets received
 in 15 minute intervals in last 5 days", $sc);

//imageline($i, 10, 10, 10, $h-10, $sc);
imageline($i, 10, 10, $w-10, 10, $sc);
imageline($i, 10, $h-10, $w-10, $h-10, $sc);
$x = 10;
$y = $h - 10;

$fd = popen ("zcat /home/tom/ping-bug.gz " .
  "| perl -ne 'print \"$1\n\" if /seq=(\d+)/'", "r");
$base = 0;
$largest = 0;
$interval = 900;
$nextinterval = $interval;
$x = 11;
while (($n = fgets ($fd)) != "") {
  // Each line is a sequence number >= 0 of a received packet.
  // Sequence numbers wrap around to 0 after 65535.
  $n += $base;
  if ($n < $largest - 1000) { $base += 65536; $n += 65536; }
  if ($n <= $largest) continue; // duplicate packet, or >1 sec rtt
  if ($n > $largest) $largest = $n;
  if ($n > $nextinterval) {
    $nextinterval += $interval;
    $newx = $x + 1;
    $newy = $h - 10 - (($h - 20) * $pings_this_interval / $interval);
    imageline($i, $x, $y, $newx, $newy, $fg);
    $x = $newx;
    $y = $newy;
    $pings_this_interval = 0;
  }
  $pings_this_interval++;
}

header("Content-Type: image/png");
imagepng($i);

?>