Annotation of loncom/cgi/barcode.png, revision 1.2

1.1       harris41    1: #!/usr/bin/perl
                      2: 
                      3: # The LearningOnline Network with CAPA
                      4: # Scott Harrison
                      5: # YEAR=2001
                      6: # 8/15
                      7: 
                      8: # A CGI script that dynamically outputs a barcode.
                      9: 
                     10: # I'm using format=Code39.
                     11: # The valid formats are
                     12: # EAN13, EAN8, UPCA, UPCE, NW7, Code39,
                     13: # ITF, IATA2of5, Matrix2of5, and COOP2of5.
                     14: 
1.2     ! harris41   15: # Example usage: /cgi-bin/barcode.gif?encode=12345*31*MSUL1
        !            16: 
1.1       harris41   17: use strict;
                     18: use GD::Barcode::Code39;
                     19: 
                     20: map {
                     21:     my ($name, $value) = split(/=/,$_);
                     22:     $value =~ tr/+/ /;
                     23:     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                     24:     if ($name eq 'encode') {
                     25: 	$ENV{'form.'.$name}=$value;
                     26:     }
                     27: } (split(/&/,$ENV{'QUERY_STRING'}));
                     28: 
                     29: # Tell the server we are sending a gif graphic
                     30: print <<END;
                     31: Content-type: image/gif
                     32: 
                     33: END
                     34: 
                     35: my $oGdBar=GD::Barcode::Code39->new($ENV{'form.encode'});
                     36: warn($GD::Barcode::errStr);
                     37: my $bindata=$oGdBar->plot->png; # create barcode image
                     38: undef $oGdBar;
                     39: binmode(STDOUT);
                     40: open OUT,"|pngtopnm|ppmtogif"; # convert into a gif image
                     41: print OUT $bindata; # output image
                     42: $|=1; # be sure to flush before closing
                     43: close OUT;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>