<commit_before>

package SGN::Controller::Barcode;

use Moose;
use GD;
use Barcode::Code128;
#use GD::Barcode::QRcode;
use Tie::UrlEncoder;

our %urlencode;

BEGIN { extends 'Catalyst::Controller'; }


sub index : Path('/barcode') Args(0) { 
    my $self =shift;
    my $c = shift;
    
    $c->stash->{template}='/barcode/index.mas';

}

sub code128_png :Path('/barcode/code128png') :Args(2) { 
    my $self = shift;
    my $c = shift;
    my $identifier = shift;
    my $text = shift;
    
    $text =~ s/\+/ /g;
    $identifier =~ s/\+/ /g;

    my $barcode_object = Barcode::Code128->new();
    $barcode_object->barcode($identifier);
    $barcode_object->font('large');
    $barcode_object->border(2);
    $barcode_object->top_margin(30);
    $barcode_object->font_align("center");
    my  $barcode = $barcode_object ->gd_image();
    my $text_width = gdLargeFont->width()*length($text);
    $barcode->string(gdLargeFont,int(($barcode->width()-$text_width)/2),10,$text, $barcode->colorAllocate(0, 0, 0));
    $c->res->headers->content_type('image/png');
    <commit_msg>add function based on get params for generating barcode images.<commit_after>

package SGN::Controller::Barcode;

use Moose;
use GD;
use Barcode::Code128;
#use GD::Barcode::QRcode;
use Tie::UrlEncoder;

our %urlencode;

BEGIN { extends 'Catalyst::Controller'; }


sub index : Path('/barcode') Args(0) { 
    my $self =shift;
    my $c = shift;
    
    $c->stash->{template}='/barcode/index.mas';

}

sub barcode_image : Path('/barcode/image') Args(0) { 
    my $self = shift;
    my $c = shift;
    
    my $code = $c->req->param("code");
    my $text = $c->req->param("text");
    my $size = $c->req->param("size");
    
    my $scale = 2;
    if ($size eq "small") { $scale = 1; }
    if ($size eq "huge") { $scale = 3; }
    
    my $barcode_object = Barcode::Code128->new();
    $barcode_object->barcode($code);
    $barcode_object->font('large');
    $barcode_object->border(2);
    $barcode_object->scale($scale);
    $barcode_object->top_margin(30);
    $barcode_object->font_align("center");
    my  $barcode = $barcode_object ->gd_image();
    my $text_width = gdLargeFont->width()*length($text);
    $barcode->string(gdLargeFont,int(($barcode->width()-$text_width)/2),10,$text, $barcode->colorAllocate(0, 0, 0));
    $c->res->headers->content_type('image/png');
    
    $c->res->body($barcode->png());    
}
    

#deprecated
sub code128_png :Path('/barcode/code128png') :Args(2) { 
    my $self = shift;
    my $c = shift;
    my $identifier = shift;
    my $text = shift;
    
    $text =~ s/\+/ /g;
    $identifier =~ s/\+/ /g;

    my $barcode_object = Barcode::Code128->new();
    $barcode_object->barcode($identifier);
    $barcode_object->font('large');
    $barcode_object->border(2);
    $barcode_object->top_margin(30);
    $barcode_object->font_align("center");
    my  $barcode = $barcode_object ->gd_image();
    my $text_width = gdLargeFont->width()*length($text);
    $barcode->string(gdLargeFont,int(($barcode->width()-$text_width)/2),10,$text, $barcode->colorAllocate(0, 0, 0));
    $c->res->headers->content_type('image/png');
    
{'fraction_non_alphanumeric': 0.19776714513556617, 'fraction_numerical': 0.019776714513556618, 'mean_word_length': 3.6736214605067063, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 59, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3924924', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1159, 'n_words': 208}