diff options
Diffstat (limited to 'mat')
-rwxr-xr-x | mat | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -14,9 +14,6 @@ use Text::Iconv; tie my %Config, "Config::Simple", '/etc/mat.conf'; -use constant LABEL_NAME => $Config{'label_name'}; -use constant LABEL_ID_PREFIX => $Config{'label_id_prefix'}; - #use Data::Dumper; my $db = DBI->connect("dbi:SQLite:recipe.db", "", "", {RaiseError => 1, @@ -188,7 +185,7 @@ sub cmd_inventory { my $sql = "SELECT recipe_id, count(recipe_id), storage FROM inventory"; $sql .= " WHERE storage='$storage'" if ( $storage ); - $sql .= " GROUP BY storage, recipe_id"; + $sql .= " GROUP BY storage, preparation_date, recipe_id"; my $all = $db->selectall_arrayref($sql); foreach my $row (@$all) { @@ -276,13 +273,18 @@ sub print_label { my $y_border = 40; my $iconv = Text::Iconv->new("UTF-8", "ISO8859-1"); - my $row0 = LABEL_NAME; + my $row0 = $Config{'label_name'}; my $row1 = $iconv->convert($dish_name); my $row2 = `date +%Y%m%d|tr -d '\n'`.' ('.$amount.'g)'; - my $idbarcode = GD::Barcode::QRcode->new(sprintf("%s%d", LABEL_ID_PREFIX, $id), { Version=>3 }); + my $idbarcode = GD::Barcode::QRcode->new(sprintf("%s%d", $Config{'label_id_prefix'}, $id), { Version=>3 }); my $idbarcode_image=$idbarcode->plot(); + my $logo; + if ($ENV{'PRINT_WITH_LOGO'}) { + $logo = GD::Image->newFromPng("layer1.png"); + } + my $idtext = new GD::Image(500, $fontsize * 2); my $white = $idtext->colorAllocate(255,255,255); my $black = $idtext->colorAllocate(0,0,0); @@ -336,10 +338,15 @@ sub print_label { $label->fill(0, 0, $white); $label->copyResized($idbarcode_image, $x_border, $y_border, 0, 0, $idbarcode_image->width() * 5, $idbarcode_image->height() * 5, $idbarcode_image->width(), $idbarcode_image->height()); - $label->copyResized($idtext, $x_border * 2, $y_border + $idbarcode_image->height() * 5, 0, 0, $idtext->width() * 2, $idtext->height() * 2, $idtext->width(), $idtext->height()); + $label->copyResized($idtext, $x_border * 3, $y_border + $idbarcode_image->height() * 5, 0, 0, $idtext->width() * 2, $idtext->height() * 2, $idtext->width(), $idtext->height()); $label->copyResized($text0_image, $label->width() - $x_border - 2 * $fontsize, $y_border, 0, 0, $bounds0[1] * 1, $bounds0[2], $bounds0[1], $bounds0[2]); $label->copyResized($text1_image, $label->width() - $x_border - 4 * $fontsize, $y_border, 0, 0, $bounds1[1] * 1, $bounds1[2], $bounds1[1], $bounds1[2]); $label->copyResized($text2_image, $label->width() - $x_border - 6 * $fontsize, $y_border, 0, 0, $bounds2[1] * 1, $bounds2[2], $bounds2[1], $bounds2[2]); + if ($ENV{'PRINT_WITH_LOGO'}) { + my ($logo_w, $logo_h ) = $logo->getBounds(); + my $vl = $logo->copyRotate90(); + $label->copy($vl, $x_border - 20, $label->height - $y_border + 20 - $logo_w, 0, 0, $logo_h, $logo_w); + } open(PNGFILE, ">label.png"); print PNGFILE $label->png; |