Annotation of loncom/cgi/barcode.png, revision 1.5
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: #
! 6: # $Id$
! 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:
46: map {
47: my ($name, $value) = split(/=/,$_);
48: $value =~ tr/+/ /;
49: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
50: if ($name eq 'encode') {
51: $ENV{'form.'.$name}=$value;
52: }
53: } (split(/&/,$ENV{'QUERY_STRING'}));
54:
55: # Tell the server we are sending a gif graphic
56: print <<END;
57: Content-type: image/gif
58:
59: END
60:
1.3 harris41 61: unless(defined($ENV{'form.encode'}) and length($ENV{'form.encode'})) {
62: $ENV{'form.encode'}='***ERROR***UNDEFINED***';
63: }
64:
1.1 harris41 65: my $oGdBar=GD::Barcode::Code39->new($ENV{'form.encode'});
1.3 harris41 66: if ($GD::Barcode::errStr or !defined($oGdBar)) {
67: warn($GD::Barcode::errStr);
68: $oGdBar=GD::Barcode::Code39->new('***ERROR***INVALID***');
69: }
1.1 harris41 70: my $bindata=$oGdBar->plot->png; # create barcode image
71: undef $oGdBar;
72: binmode(STDOUT);
1.3 harris41 73: open OUT,"|pngtopnm|ppmtogif 2>/dev/null"; # convert into gif image
1.1 harris41 74: print OUT $bindata; # output image
75: $|=1; # be sure to flush before closing
76: close OUT;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>