#!/usr/bin/perl # The LearningOnline Network with CAPA # Scott Harrison # YEAR=2001 # 8/15 # A CGI script that dynamically outputs a barcode. # I'm using format=Code39. # The valid formats are # EAN13, EAN8, UPCA, UPCE, NW7, Code39, # ITF, IATA2of5, Matrix2of5, and COOP2of5. # Example usage: /cgi-bin/barcode.gif?encode=12345*31*MSUL1 use strict; use GD::Barcode::Code39; map { 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; } } (split(/&/,$ENV{'QUERY_STRING'})); # Tell the server we are sending a gif graphic print <new($ENV{'form.encode'}); if ($GD::Barcode::errStr or !defined($oGdBar)) { warn($GD::Barcode::errStr); $oGdBar=GD::Barcode::Code39->new('***ERROR***INVALID***'); } 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;