Annotation of loncom/cgi/barcode.png, revision 1.12
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.12 ! albertel 6: # $Id: barcode.png,v 1.11 2003/02/03 18:03:52 harris41 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: #
30: ###
1.1 harris41 31:
32: # I'm using format=Code39.
33: # The valid formats are
34: # EAN13, EAN8, UPCA, UPCE, NW7, Code39,
35: # ITF, IATA2of5, Matrix2of5, and COOP2of5.
36:
1.2 harris41 37: # Example usage: /cgi-bin/barcode.gif?encode=12345*31*MSUL1
38:
1.1 harris41 39: use strict;
40: use GD::Barcode::Code39;
41:
1.7 matthew 42: $|=1; # Autoflush after each print/write
1.12 ! albertel 43: my %env;
1.6 harris41 44: foreach (split(/&/,$ENV{'QUERY_STRING'})) {
1.1 harris41 45: my ($name, $value) = split(/=/,$_);
46: $value =~ tr/+/ /;
47: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
48: if ($name eq 'encode') {
1.12 ! albertel 49: $env{'form.'.$name}=$value;
1.1 harris41 50: }
1.6 harris41 51: }
1.1 harris41 52:
1.10 albertel 53: # Tell the server we are sending a png graphic
1.1 harris41 54: print <<END;
1.10 albertel 55: Content-type: image/png
1.1 harris41 56:
57: END
58:
1.12 ! albertel 59: unless(defined($env{'form.encode'}) and length($env{'form.encode'})) {
! 60: $env{'form.encode'}='***ERROR***UNDEFINED***';
1.3 harris41 61: }
1.12 ! albertel 62: my $text = '*'.uc($env{'form.encode'}).'*';
1.8 matthew 63: my $oGdBar=GD::Barcode::Code39->new($text);
1.3 harris41 64: if ($GD::Barcode::errStr or !defined($oGdBar)) {
65: warn($GD::Barcode::errStr);
66: $oGdBar=GD::Barcode::Code39->new('***ERROR***INVALID***');
67: }
1.1 harris41 68: my $bindata=$oGdBar->plot->png; # create barcode image
69: undef $oGdBar;
70: binmode(STDOUT);
1.10 albertel 71: #open OUT,"|pngtopnm|ppmtogif 2>/dev/null"; # convert into gif image
72: #print OUT $bindata; # output image
73: #$|=1; # be sure to flush before closing
74: #close OUT;
75: print $bindata;
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>