1 package SGN
::Controller
::LabelDesigner
;
7 use URI
::Encode
qw(uri_encode uri_decode);
8 use URI
::FromHash
'uri';
10 BEGIN { extends
'Catalyst::Controller'; }
12 sub interactive_barcoder_main
:Path
('/tools/label_designer') Args
(0) {
16 if (!$c->user()) { # redirect to login page
17 $c->res->redirect( uri
( path
=> '/solpeople/login.pl', query
=> { goto_url
=> $c->req->uri->path_query } ) );
21 $c->stash->{template
} = '/tools/label_designer.mas';
24 sub barcode_preview
:Path
('/tools/label_designer/preview') {
27 my $uri = URI
::Encode
->new( { encode_reserved
=> 0 } );
28 my $content = $uri->decode($c->req->param("content"));
29 my $type = $uri->decode($c->req->param("type"));
30 my $size = $uri->decode($c->req->param("size"));
32 #print STDERR "Content is $content and type is $type and size is $size\n";
34 if ($type eq 'Code128') {
36 print STDERR
"Creating barcode 128\n";
38 my $barcode_object = Barcode
::Code128
->new();
39 $barcode_object->option("scale", $size);
40 $barcode_object->option("font_align", "center");
41 $barcode_object->option("padding", 5);
42 $barcode_object->option("show_text", 0);
43 $barcode_object->barcode($content);
44 my $barcode = $barcode_object->gd_image();
46 $c->res->headers->content_type('image/png');
47 $c->res->body($barcode->png());
49 } elsif ($type eq 'QRCode') {
51 print STDERR
"Creating QR Code\n";
53 $c->tempfiles_subdir('barcode');
54 my ($file_location, $uri) = $c->tempfile( TEMPLATE
=> [ 'barcode', 'bc-XXXXX'], SUFFIX
=>'.jpg');
56 my $barcode_generator = CXGN
::QRcode
->new(
63 my $barcode_file = $barcode_generator->get_barcode_file($file_location);
65 my $qrcode_path = $c->path_to($uri);
67 $c->res->headers->content_type('image/jpg');
68 my $output = read_file
($qrcode_path);
69 $c->res->body($output);