summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcos <cos>2013-01-27 23:10:48 +0100
committercos <cos>2013-01-27 23:10:48 +0100
commita5f94c6e48ded2ba6a1e7c14a8d6a9c999baca0d (patch)
treed1747d0f16231fc5bc7e919904ed70241a59dd46
parent94eb3784edef854e8d0db00aaed1278ac13b5904 (diff)
downloadmat-a5f94c6e48ded2ba6a1e7c14a8d6a9c999baca0d.zip
Generate a smaller label than the default size of 29x90 mm.
-rwxr-xr-xmat90
1 files changed, 61 insertions, 29 deletions
diff --git a/mat b/mat
index cb0a41f..bd7d255 100755
--- a/mat
+++ b/mat
@@ -267,44 +267,76 @@ sub cmd_postpone {
sub print_label {
my ( $id, $dish_name, $amount ) = @_;
- my $iconv = Text::Iconv->new("UTF-8", "ISO8859-1");
- my $row0 = `date +%Y%m%d|tr -d '\n'`.' '.LABEL_NAME;
- my $row1 = $iconv->convert($dish_name).' ('.$amount.'g)';
-
- # 300 dpi & 29 x 90 mm ger: 300*2.9/2.54 = 343, 300*9.0/2.54 = 1063
- my $label = new GD::Image(343, 1063);
- my $x_border = 25;
- my $y_border = 80;
+ my $fontname = "/usr/share/fonts/truetype/freefont/FreeSans.ttf";
+ my $fontsize = 15;
+ my $x_border = 40;
+ my $y_border = 450;
- my $white = $label->colorAllocate(255,255,255);
- my $black = $label->colorAllocate(0,0,0);
-
- $label->fill(0, 0, $white);
+ my $iconv = Text::Iconv->new("UTF-8", "ISO8859-1");
+ my $row0 = 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_image=$idbarcode->plot();
- $label->copyResized($idbarcode_image, $x_border, $y_border, 0, 0, $idbarcode_image->width() * 5, $idbarcode_image->height() * 5, $idbarcode_image->width(), $idbarcode_image->height());
- my $idtext = new GD::Image(500, gdGiantFont->height());
- $white = $idtext->colorAllocate(255,255,255);
- $black = $idtext->colorAllocate(0,0,0);
+
+ my $idtext = new GD::Image(500, $fontsize * 2);
+ my $white = $idtext->colorAllocate(255,255,255);
+ my $black = $idtext->colorAllocate(0,0,0);
$idtext->fill(1, 1, $white);
$idtext->string(gdGiantFont, 0, 0, $id, $black);
- $label->copyResized($idtext, $x_border * 2, $y_border + $idbarcode_image->height() * 5, 0, 0, $idtext->width() * 2, $idtext->height() * 2, $idtext->width(), $idtext->height());
- my $text = new GD::Image(500, gdGiantFont->height());
- $white = $text->colorAllocate(255,255,255);
- $black = $text->colorAllocate(0,0,0);
- $text->fill(1, 1, $white);
- $text->string(gdGiantFont, 0, 0, $row0, $black);
- my $text_image=$text->copyRotate90();
- $text_image->line(0, 0, 100, 100, $white);
+ my $text0 = new GD::Image(500, $fontsize * 3);
+ $white = $text0->colorAllocate(255,255,255);
+ $black = $text0->colorAllocate(0,0,0);
+ $text0->fill(1, 1, $white);
+ my @bounds0 = $text0->stringFT(-1 * $black, $fontname, $fontsize, 0, 0, 2 * $fontsize, $row0);
+ my $text0_image=$text0->copyRotate90();
+ $text0_image->line(0, 0, 100, 100, $white);
+
+ my $text1 = new GD::Image(500, $fontsize * 3);
+ $white = $text1->colorAllocate(255,255,255);
+ $black = $text1->colorAllocate(0,0,0);
+ $text1->fill(1, 1, $white);
+ $text1->filledRectangle(0, 0, $text1->width(), $text1->height(), $white);
+ my @bounds1 = $text1->stringFT(-1 * $black, $fontname, $fontsize, 0, 0, 2 * $fontsize, $row1);
+ my $text1_image=$text1->copyRotate90();
+
+ my $text2 = new GD::Image(500, $fontsize * 3);
+ $white = $text2->colorAllocate(255,255,255);
+ $black = $text2->colorAllocate(0,0,0);
+ $text2->fill(1, 1, $white);
+ $text2->filledRectangle(0, 0, $text2->width(), $text2->height(), $white);
+ my @bounds2 = $text2->stringFT(-1 * $black, $fontname, $fontsize, 0, 0, 2 * $fontsize, $row2);
+ my $text2_image=$text2->copyRotate90();
+
+ my $labelwidth = $idbarcode_image->width() * 5 + $idtext->height() * 2 + 2 * $y_border;
+ if($bounds0[2] + 2 * $y_border > $labelwidth) {
+ $labelwidth = $bounds0[2] + 2 * $y_border;
+ }
+ if($bounds1[2] + 2 * $y_border > $labelwidth) {
+ $labelwidth = $bounds1[2] + 2 * $y_border;
+ }
+ if($bounds2[2] + 2 * $y_border > $labelwidth) {
+ $labelwidth = $bounds2[2] + 2 * $y_border;
+ }
+ if($labelwidth > 1063)
+ {
+ $labelwidth = 1063;
+ }
- $label->copyResized($text_image, $label->width() - $text_image->width() * 4 - $x_border, $y_border, 0, 0, $text_image->width() * 4, $text_image->height() * 3, $text_image->width(), $text_image->height());
+ # 300 dpi & 29 x 90 mm ger: 300*2.9/2.54 = 343, 300*9.0/2.54 = 1063
+ my $label = new GD::Image(343, $labelwidth);
- $text->filledRectangle(0, 0, $text->width(), $text->height(), $white);
- $text->string(gdGiantFont, 0, 0, $row1, $black);
- $text_image=$text->copyRotate90();
- $label->copyResized($text_image, $label->width() - $text_image->width() * 4 - 4 * gdGiantFont->height() - $x_border, $y_border, 0, 0, $text_image->width() * 4, $text_image->height() * 3, $text_image->width(), $text_image->height());
+ $white = $label->colorAllocate(255,255,255);
+ $black = $label->colorAllocate(0,0,0);
+ $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($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]);
open(PNGFILE, ">label.png");
print PNGFILE $label->png;