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

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: 
        !            15: use strict;
        !            16: use GD::Barcode::Code39;
        !            17: 
        !            18: map {
        !            19:     my ($name, $value) = split(/=/,$_);
        !            20:     $value =~ tr/+/ /;
        !            21:     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
        !            22:     if ($name eq 'encode') {
        !            23: 	$ENV{'form.'.$name}=$value;
        !            24:     }
        !            25: } (split(/&/,$ENV{'QUERY_STRING'}));
        !            26: 
        !            27: # Tell the server we are sending a gif graphic
        !            28: print <<END;
        !            29: Content-type: image/gif
        !            30: 
        !            31: END
        !            32: 
        !            33: my $oGdBar=GD::Barcode::Code39->new($ENV{'form.encode'});
        !            34: warn($GD::Barcode::errStr);
        !            35: my $bindata=$oGdBar->plot->png; # create barcode image
        !            36: undef $oGdBar;
        !            37: binmode(STDOUT);
        !            38: open OUT,"|pngtopnm|ppmtogif"; # convert into a gif image
        !            39: print OUT $bindata; # output image
        !            40: $|=1; # be sure to flush before closing
        !            41: close OUT;

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