--- loncom/cgi/barcode.png 2001/12/11 19:32:03 1.5 +++ loncom/cgi/barcode.png 2005/04/07 06:56:21 1.12 @@ -1,9 +1,9 @@ #!/usr/bin/perl # The LearningOnline Network with CAPA -# barcode.gif - A CGI script that dynamically outputs a barcode. +# barcode.png - A CGI script that dynamically outputs a barcode. # -# $Id: barcode.png,v 1.5 2001/12/11 19:32:03 harris41 Exp $ +# $Id: barcode.png,v 1.12 2005/04/07 06:56:21 albertel Exp $ # # Copyright Michigan State University Board of Trustees # @@ -27,10 +27,6 @@ # # http://www.lon-capa.org/ # -# Scott Harrison -# YEAR=2001 -# 8/15,9/28,12/11 -# ### # I'm using format=Code39. @@ -43,26 +39,28 @@ use strict; use GD::Barcode::Code39; -map { +$|=1; # Autoflush after each print/write +my %env; +foreach (split(/&/,$ENV{'QUERY_STRING'})) { my ($name, $value) = split(/=/,$_); $value =~ tr/+/ /; $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg; if ($name eq 'encode') { - $ENV{'form.'.$name}=$value; + $env{'form.'.$name}=$value; } -} (split(/&/,$ENV{'QUERY_STRING'})); +} -# Tell the server we are sending a gif graphic +# Tell the server we are sending a png graphic print <new($ENV{'form.encode'}); +my $text = '*'.uc($env{'form.encode'}).'*'; +my $oGdBar=GD::Barcode::Code39->new($text); if ($GD::Barcode::errStr or !defined($oGdBar)) { warn($GD::Barcode::errStr); $oGdBar=GD::Barcode::Code39->new('***ERROR***INVALID***'); @@ -70,7 +68,8 @@ if ($GD::Barcode::errStr or !defined($oG my $bindata=$oGdBar->plot->png; # create barcode image undef $oGdBar; binmode(STDOUT); -open OUT,"|pngtopnm|ppmtogif 2>/dev/null"; # convert into gif image -print OUT $bindata; # output image -$|=1; # be sure to flush before closing -close OUT; +#open OUT,"|pngtopnm|ppmtogif 2>/dev/null"; # convert into gif image +#print OUT $bindata; # output image +#$|=1; # be sure to flush before closing +#close OUT; +print $bindata;