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

1.1       harris41    1: #!/usr/bin/perl
                      2: 
                      3: # The LearningOnline Network with CAPA
                      4: # Scott Harrison
                      5: # YEAR=2001
1.4     ! harris41    6: # 8/15,9/28
1.1       harris41    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: 
1.3       harris41   35: unless(defined($ENV{'form.encode'}) and length($ENV{'form.encode'})) {
                     36:     $ENV{'form.encode'}='***ERROR***UNDEFINED***';
                     37: }
                     38: 
1.1       harris41   39: my $oGdBar=GD::Barcode::Code39->new($ENV{'form.encode'});
1.3       harris41   40: if ($GD::Barcode::errStr or !defined($oGdBar)) {
                     41:     warn($GD::Barcode::errStr);
                     42:     $oGdBar=GD::Barcode::Code39->new('***ERROR***INVALID***');
                     43: }
1.1       harris41   44: my $bindata=$oGdBar->plot->png; # create barcode image
                     45: undef $oGdBar;
                     46: binmode(STDOUT);
1.3       harris41   47: open OUT,"|pngtopnm|ppmtogif 2>/dev/null"; # convert into gif image
1.1       harris41   48: print OUT $bindata; # output image
                     49: $|=1; # be sure to flush before closing
                     50: close OUT;

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