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

1.1       harris41    1: #!/usr/bin/perl
                      2: 
                      3: # The LearningOnline Network with CAPA
1.5       harris41    4: # barcode.gif - A CGI script that dynamically outputs a barcode.
                      5: #
1.8     ! matthew     6: # $Id: barcode.gif,v 1.7 2001/12/21 14:45:36 matthew Exp $
1.5       harris41    7: #
                      8: # Copyright Michigan State University Board of Trustees
                      9: #
                     10: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
                     11: #
                     12: # LON-CAPA is free software; you can redistribute it and/or modify
                     13: # it under the terms of the GNU General Public License as published by
                     14: # the Free Software Foundation; either version 2 of the License, or
                     15: # (at your option) any later version.
                     16: #
                     17: # LON-CAPA is distributed in the hope that it will be useful,
                     18: # but WITHOUT ANY WARRANTY; without even the implied warranty of
                     19: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
                     20: # GNU General Public License for more details.
                     21: #
                     22: # You should have received a copy of the GNU General Public License
                     23: # along with LON-CAPA; if not, write to the Free Software
                     24: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
                     25: #
                     26: # /home/httpd/html/adm/gpl.txt
                     27: #
                     28: # http://www.lon-capa.org/
                     29: #
1.1       harris41   30: # Scott Harrison
                     31: # YEAR=2001
1.5       harris41   32: # 8/15,9/28,12/11
                     33: #
                     34: ###
1.1       harris41   35: 
                     36: # I'm using format=Code39.
                     37: # The valid formats are
                     38: # EAN13, EAN8, UPCA, UPCE, NW7, Code39,
                     39: # ITF, IATA2of5, Matrix2of5, and COOP2of5.
                     40: 
1.2       harris41   41: # Example usage: /cgi-bin/barcode.gif?encode=12345*31*MSUL1
                     42: 
1.1       harris41   43: use strict;
                     44: use GD::Barcode::Code39;
                     45: 
1.7       matthew    46: $|=1;   # Autoflush after each print/write
1.6       harris41   47: foreach (split(/&/,$ENV{'QUERY_STRING'})) {
1.1       harris41   48:     my ($name, $value) = split(/=/,$_);
                     49:     $value =~ tr/+/ /;
                     50:     $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
                     51:     if ($name eq 'encode') {
                     52: 	$ENV{'form.'.$name}=$value;
                     53:     }
1.6       harris41   54: }
1.1       harris41   55: 
                     56: # Tell the server we are sending a gif graphic
                     57: print <<END;
                     58: Content-type: image/gif
                     59: 
                     60: END
                     61: 
1.3       harris41   62: unless(defined($ENV{'form.encode'}) and length($ENV{'form.encode'})) {
                     63:     $ENV{'form.encode'}='***ERROR***UNDEFINED***';
                     64: }
1.8     ! matthew    65: my $text = '*'.$ENV{'form.encode'}.'*';
        !            66: my $oGdBar=GD::Barcode::Code39->new($text);
1.3       harris41   67: if ($GD::Barcode::errStr or !defined($oGdBar)) {
                     68:     warn($GD::Barcode::errStr);
                     69:     $oGdBar=GD::Barcode::Code39->new('***ERROR***INVALID***');
                     70: }
1.1       harris41   71: my $bindata=$oGdBar->plot->png; # create barcode image
                     72: undef $oGdBar;
                     73: binmode(STDOUT);
1.3       harris41   74: open OUT,"|pngtopnm|ppmtogif 2>/dev/null"; # convert into gif image
1.1       harris41   75: print OUT $bindata; # output image
                     76: $|=1; # be sure to flush before closing
                     77: close OUT;

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