Jump to content

Labels: Difference between revisions

From base48
Klubko (talk | contribs)
No edit summary
Thebys (talk | contribs)
mNo edit summary
 
(8 intermediate revisions by the same user not shown)
Line 1: Line 1:
== QR codes ==
== QR codes ==
[[File:Label Richard.jpg|thumb|Example of a real label used in Base48.]]
Thebys' Brother printer can print monochrome PNG files of height 128px.
Thebys' Brother printer can print monochrome PNG files of height 128px.


=== Creating the PNG files ===
=== Creating the PNG files ===
One way to do it is with this simple Perl script:
One way to do it is with this simple Perl script:<syntaxhighlight lang="perl" line="1" start="0">use GD::Barcode::QRcode;
use GD;


use GD::Barcode::QRcode;
use strict;
use GD;
use warnings;
use strict;
use warnings;
my $large = '/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf';
my $narrow = '/usr/share/fonts/truetype/liberation/LiberationSansNarrow-Regular.ttf';
my ($img, $w, $h);
sub text
{
my $font = shift;
if ($img) {
$img->stringFT(-1,$font,@_) or die "$font: $@: $!";
} else {
my @bounds = GD::Image->stringFT(-1,$font,@_) or die "$font: $@: $!";
my $nw = $bounds[2] + 16;
$w = $nw if $nw > $w;
}
}
sub render
{
my $t = shift;
my $title = shift;
my $text = shift;
my $url = shift // $text;
my $m = 3;
$img = undef;
$h = $t;
$w = $h;
# Sizing first
if ($t == 76) {
text($narrow,32,0,$h+8,0, $text);
} else {
text($large,48,0,$h+8,0, $title);
text($narrow,24,0,$h+8,0, $text);
}
# Actual rendering
$img = GD::Image->new($w,$h);
my $qr = GD::Barcode::QRcode->new($url)->plot(Height => $h);
$img->copyResized($qr, 0, 0, $m, $m, $img->height, $img->height, $qr->width-2*$m, $qr->height-2*$m);
if ($t == 76) {
text($narrow,32,0,$img->height+8, $img->height-24, $text);
} else {
text($large,48,0,$img->height+8, 64, $title);
text($narrow,24,0,$img->height+8, $img->height-16, $text);
}
return $img;
}
sub do_one
{
my $title = shift;
my $str = shift // $title;
open my $big, ">$str.png" or die "$str.png: $!";
print $big render (128, $title, "https://wiki.base48.cz/wiki/$str")->png;
open my $small, ">small-$str.png" or die "$str.png: $!";
print $small render (76, $title, "/wiki/$str", "https://wiki.base48.cz/wiki/$str")->png;
}
do_one('Electro Lab', 'Electro_lab');
do_one('RGB LED Panel', 'Buse_RGB_LED_Panel');
do_one('3D Printers', '3D_printing_lab');
do_one('C64', 'C64');
do_one('Color Jet Printer', 'Color_Jet_Printer');
do_one('CNC', 'CNC');
do_one('Metal Workshop', 'Metal_workshop');
do_one('Woodworking', 'Woodworking');
do_one('Turtle Drawing Plotter', 'PlotBot');
do_one('Bike Repair Corner', 'Bike_corner');
do_one('Library', 'Library');
do_one('Output Buffer', 'OutputBuffer');
do_one('Making QR labels', 'Labels#QR_codes');
do_one('Bongs', 'Bongs#Bongo');
do_one('Bong Cleaning Tools', 'Bongs#Maintenance');


=== Printing them out: ===
my $large = '/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf';
Use this tool: https://git.familie-radermacher.ch/linux/ptouch-print.git
my $narrow = '/usr/share/fonts/truetype/liberation/LiberationSansNarrow-Regular.ttf';
 
my ($img, $w, $h);
 
sub text
{
my $font = shift;
if ($img) {
$img->stringFT(-1,$font,@_) or die "$font: $@: $!";
} else {
my @bounds = GD::Image->stringFT(-1,$font,@_) or die "$font: $@: $!";
my $nw = $bounds[2] + 16;
$w = $nw if $nw > $w;
}
}
 
sub render
{
my $t = shift;
my $title = shift;
my $text = shift;
my $url = shift // $text;
my $m = 3;
 
$img = undef;
$h = $t;
$w = $h;
 
# Sizing first
if ($t == 76) {
text($narrow,32,0,$h+8,0, $text);
} else {
text($large,48,0,$h+8,0, $title);
text($narrow,24,0,$h+8,0, $text);
}
 
# Actual rendering
$img = GD::Image->new($w,$h);
my $qr = GD::Barcode::QRcode->new($url)->plot(Height => $h);
$img->copyResized($qr, 0, 0, $m, $m, $img->height, $img->height, $qr->width-2*$m, $qr->height-2*$m);
 
if ($t == 76) {
text($narrow,32,0,$img->height+8, $img->height-24, $text);
} else {
text($large,48,0,$img->height+8, 64, $title);
text($narrow,24,0,$img->height+8, $img->height-16, $text);
}
 
return $img;
}
 
sub do_one
{
my $title = shift;
my $str = shift // $title;
 
open my $big, ">$str.png" or die "$str.png: $!";
print $big render (128, $title, "https://wiki.base48.cz/wiki/$str")->png;


# perl makeqr.pl
# ./ptouch-print --image=Library.png


Minimize waste by chaining multiple labels:
open my $small, ">small-$str.png" or die "$str.png: $!";
print $small render (76, $title, "/wiki/$str", "https://wiki.base48.cz/wiki/$str")->png;
}


# ./ptouch-print --image=CNC.png --chain
do_one('Electro Lab', 'Electro_lab');
# ./ptouch-print --image=Library.png --precut -chain
do_one('RGB LED Panel', 'Buse_RGB_LED_Panel');
# ./ptouch-print --image=OutputBuffer.png --precut
do_one('3D Printers', '3D_printing_lab');
do_one('C64', 'C64');
do_one('Color Jet Printer', 'Color_Jet_Printer');
do_one('CNC', 'CNC');
do_one('Metal Workshop', 'Metal_workshop');
do_one('Woodworking', 'Woodworking');
do_one('Turtle Drawing Plotter', 'PlotBot');
do_one('Bike Repair Corner', 'Bike_corner');
do_one('Library', 'Library');
do_one('Output Buffer', 'OutputBuffer');
do_one('Making QR labels', 'Labels#QR_codes');
do_one('Bongs', 'Bongs#Bongo');
do_one('Bong Cleaning Tools', 'Bongs#Maintenance');</syntaxhighlight>
=== Printing them out: ===
Use this tool: https://git.familie-radermacher.ch/linux/ptouch-print.git<syntaxhighlight lang="shell" line="1">
# perl makeqr.pl
# ./ptouch-print --image=Library.png
</syntaxhighlight>Minimize waste by chaining multiple labels:<syntaxhighlight lang="shell" line="1">
# ./ptouch-print --image=CNC.png --chain  
# ./ptouch-print --image=Library.png --precut --chain  
# ./ptouch-print --image=OutputBuffer.png --precut
</syntaxhighlight>

Latest revision as of 20:50, 22 March 2026

QR codes

Example of a real label used in Base48.

Thebys' Brother printer can print monochrome PNG files of height 128px.

Creating the PNG files

One way to do it is with this simple Perl script:

use GD::Barcode::QRcode;
use GD;

use strict;
use warnings;

my $large = '/usr/share/fonts/truetype/liberation/LiberationSans-Regular.ttf';
my $narrow = '/usr/share/fonts/truetype/liberation/LiberationSansNarrow-Regular.ttf';

my ($img, $w, $h);

sub text
{
	my $font = shift;
	if ($img) {
		$img->stringFT(-1,$font,@_) or die "$font: $@: $!";
	} else {
		my @bounds = GD::Image->stringFT(-1,$font,@_) or die "$font: $@: $!";
		my $nw = $bounds[2] + 16;
		$w = $nw if $nw > $w;
	}
}

sub render
{
	my $t = shift;
	my $title = shift;
	my $text = shift;
	my $url = shift // $text;
	my $m = 3;

	$img = undef;
	$h = $t;
	$w = $h;

	# Sizing first
	if ($t == 76) {
		text($narrow,32,0,$h+8,0, $text);
	} else {
		text($large,48,0,$h+8,0, $title);
		text($narrow,24,0,$h+8,0, $text);
	}

	# Actual rendering
	$img = GD::Image->new($w,$h);
	my $qr = GD::Barcode::QRcode->new($url)->plot(Height => $h);
	$img->copyResized($qr, 0, 0, $m, $m, $img->height, $img->height, $qr->width-2*$m, $qr->height-2*$m);

	if ($t == 76) {
		text($narrow,32,0,$img->height+8, $img->height-24, $text);
	} else {
		text($large,48,0,$img->height+8, 64, $title);
		text($narrow,24,0,$img->height+8, $img->height-16, $text);
	}

	return $img;
}

sub do_one
{
	my $title = shift;
	my $str = shift // $title;

	open my $big, ">$str.png" or die "$str.png: $!";
	print $big render (128, $title, "https://wiki.base48.cz/wiki/$str")->png;


	open my $small, ">small-$str.png" or die "$str.png: $!";
	print $small render (76, $title, "/wiki/$str", "https://wiki.base48.cz/wiki/$str")->png;
}

do_one('Electro Lab', 'Electro_lab');
do_one('RGB LED Panel', 'Buse_RGB_LED_Panel');
do_one('3D Printers', '3D_printing_lab');
do_one('C64', 'C64');
do_one('Color Jet Printer', 'Color_Jet_Printer');
do_one('CNC', 'CNC');
do_one('Metal Workshop', 'Metal_workshop');
do_one('Woodworking', 'Woodworking');
do_one('Turtle Drawing Plotter', 'PlotBot');
do_one('Bike Repair Corner', 'Bike_corner');
do_one('Library', 'Library');
do_one('Output Buffer', 'OutputBuffer');
do_one('Making QR labels', 'Labels#QR_codes');
do_one('Bongs', 'Bongs#Bongo');
do_one('Bong Cleaning Tools', 'Bongs#Maintenance');

Printing them out:

Use this tool: https://git.familie-radermacher.ch/linux/ptouch-print.git

# perl makeqr.pl
# ./ptouch-print --image=Library.png

Minimize waste by chaining multiple labels:

# ./ptouch-print --image=CNC.png --chain 
# ./ptouch-print --image=Library.png --precut --chain 
# ./ptouch-print --image=OutputBuffer.png --precut