#!/usr/bin/perl use strict; use warnings; use GD; use Getopt::Long qw/:config auto_help gnu_getopt bundling/; use Pod::Usage; use List::Util qw/max min/; use Data::Dumper; use GdUtil qw/:all/; use PTouch qw/pixels/; my $outfile = "label.png"; my $qrfile = undef; my $text = ''; my $qrtext = ""; #$qrtext = "MECARD:N:Meacham,John;TEL:626-379-6981;EMAIL:john\@foo.net;;"; #my $name = "John Meacham"; #my $number = "626-379-6981"; #my $email = "john\@foo.net"; # tape width in mm my $tapewidth = 12; my $datamatrix = 0; my $minquality = 'L'; my $margin = 2; my $scale = undef; my $force = 0; GetOptions( "w=n" => \$tapewidth, # width of tape "o=s" => \$outfile, "s=f" => \$scale, "m" => \$datamatrix, "c=s" => \$qrtext, "q=s" => \$minquality, "t=s" => \$text, "M=n" => \$margin, "qrfile=s" => \$qrfile, "force" => \$force, ) or die "invalid options"; hspace(1)->useFontConfig(1); my $codeside = pixels($tapewidth) or die "invalid tapewidth: $tapewidth"; my $code = $datamatrix ? createcode_dm($qrtext) : createcode_qr($qrtext, quality => $minquality); $code->useFontConfig(1); printf "QRBounds(%i,%i)\n", $code->getBounds; my ($cbw,$cbh) = $code->getBounds(); $code = crop_centered($code,$cbw + 2*max(4,$margin) - 8, $cbh + 2*$margin - 8); printf "modified QRBounds(%i,%i)\n", $code->getBounds(); writepng($code, $qrfile) if $qrfile; my ($cw,$ch) = $code->getBounds(); if (!defined $scale) { my $factor = $codeside / $ch; $scale = $factor < 3.5 ? int($factor) : $factor; printf "Scale factor: %.4f -> %.4f\n",$factor, $scale; die "computed scale is too small to create readable code." if $scale < 2 && !$force; } #my $tgd = drawtext($text); print Dumper(drawtext($name), vspace(1), drawtext($number, font => 'Times:Italic', size => 16), vspace(1), drawtext($email, size => 16)); my $tgd = vcat(drawtext($name), vspace(1), drawtext($number, font => 'Times:Italic', size => 16), vspace(1), drawtext($email, size => 16)); #print "$tgd\n"; my ($tw,$th) = $tgd->getBounds(); my $cs = $scale * $ch; my $extra = max(0,$scale * (4 - $margin)); my $img = hcat(hspace($scale*4), $tgd, stretch($code,$scale)); writepng(crop_centered($img,undef, $codeside), $outfile); __END__ =head1 SYNOPSIS Options: --help brief help message -s n force a specific scale factor -m use DataMatrix instead of qr code -w n specify tape width in mm -M n number of margin units around code