Skip to content

Instantly share code, notes, and snippets.

@issm
Created February 17, 2011 01:10
Show Gist options
  • Save issm/830712 to your computer and use it in GitHub Desktop.
Save issm/830712 to your computer and use it in GitHub Desktop.
generates EAN13/Code39 barcode easily.
plackup -s Starman --port 5000 -MGD::Barcode -MGD::Image -MPlack::Request -e 'my $app = sub { my $q = Plack::Request->new(shift)->query_parameters(); my ($c,$m,$r,$h,$nt) = split(/:/,$q->get("q")||""); my $bc = GD::Barcode->new($m||"EAN13",$c) or return [500,["Content-Type"=>"text/plain"],[$GD::Barcode::errStr]]; my ($i0,$i1) = ($bc->plot(Height=>$h,NoText=>$nt)); my ($w0,$h0) = $i0->getBounds(); my ($w1,$h1) = (int($w0*($r||1)),int($h0*($r||1))); $i1 = GD::Image->new($w1,$h1); $i1->copyResized($i0,0,0,0,0,$w1,$h1,$w0,$h0); return [200,["Content-Type"=>"image/png"],[$i1->png]]; }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment