SPUG: Point and click GD/CGI

Sanford Morton smorton at pobox.com
Fri Jan 28 17:20:20 CST 2000


Ryan hasn't posted his demo yet from the last E-Spug meeting, so I
wrote a simple one over lunch. His was much cooler so I hope we get to
see it. Save both files in the same cgi-enabled web directory.
s/gif/png/g; in the second file if you have a more recent version of
GD. 

Oh, this thing draws a point wherever you click on the image.

--Sandy

#############################################
#!/usr/bin/perl
# filename: "click.cgi"

use CGI::Carp qw(fatalsToBrowser carpout);
use CGI;
my $q = new CGI; 

my $web_form = <<"HERE"; 
  <FORM METHOD=POST>
  Click the image to draw a point. 
  <input type=image src="image.cgi?asddsa">
  <input type=hidden name=points value="asddsa">
HERE
; 

my $points = $q->param('points');
$points .= ';' if $points;
$points .= $q->param('x') . ',' . $q->param('y') if $q->param('x');
$web_form =~ s/asddsa/$points/g;

print "Cache-Control: no-cache\nContent-Type: text/html\n\n";
print "$web_form<p>$points";
#############################################

#############################################
#!/usr/bin/perl
# filename: "image.cgi"

use GD;
$im = new GD::Image(200,200); 
$white = $im->colorAllocate(255,255,255);
$black = $im->colorAllocate(0,0,0);

for (split /;/, $ENV{'QUERY_STRING'}) {
  /(.*),(.*)/;
  $im->arc($1,$2,5,5,0,360,$black);
}         

print "Cache-Control: no-cache\nContent-Type: image/gif\n\n";
print $im->gif;
#############################################



 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
    POST TO: spug-list at pm.org        PROBLEMS: owner-spug-list at pm.org
 Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
 SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
        Email to majordomo at pm.org: ACTION spug-list your_address





More information about the spug-list mailing list