Annotation of loncom/cgi/barcode.png, revision 1.11
1.1 harris41 1: #!/usr/bin/perl
2:
3: # The LearningOnline Network with CAPA
1.10 albertel 4: # barcode.png - A CGI script that dynamically outputs a barcode.
1.5 harris41 5: #
1.11 ! harris41 6: # $Id: barcode.png,v 1.10 2002/12/13 21:33:30 albertel 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: # YEAR=2001
1.5 harris41 31: # 8/15,9/28,12/11
32: #
33: ###
1.1 harris41 34:
35: # I'm using format=Code39.
36: # The valid formats are
37: # EAN13, EAN8, UPCA, UPCE, NW7, Code39,
38: # ITF, IATA2of5, Matrix2of5, and COOP2of5.
39:
1.2 harris41 40: # Example usage: /cgi-bin/barcode.gif?encode=12345*31*MSUL1
41:
1.1 harris41 42: use strict;
43: use GD::Barcode::Code39;
44:
1.7 matthew 45: $|=1; # Autoflush after each print/write
1.6 harris41 46: foreach (split(/&/,$ENV{'QUERY_STRING'})) {
1.1 harris41 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: }
1.6 harris41 53: }
1.1 harris41 54:
1.10 albertel 55: # Tell the server we are sending a png graphic
1.1 harris41 56: print <<END;
1.10 albertel 57: Content-type: image/png
1.1 harris41 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: }
1.9 matthew 64: my $text = '*'.uc($ENV{'form.encode'}).'*';
1.8 matthew 65: my $oGdBar=GD::Barcode::Code39->new($text);
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.10 albertel 73: #open OUT,"|pngtopnm|ppmtogif 2>/dev/null"; # convert into gif image
74: #print OUT $bindata; # output image
75: #$|=1; # be sure to flush before closing
76: #close OUT;
77: print $bindata;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>