#!/usr/bin/env perl use strict; use warnings; use Text::QRCode; my $qr = Text::QRCode->new()->plot("YAPH"); my $pixelsize = 15; print '', "\n"; my $firstline = 1; my $saved = 0; foreach my $line (@{$qr}) { print ""; my $firstelem = 1; my $width = 0; my $color = ''; my $firstblockinline = 1; foreach my $elem (@{$line}) { if($firstline) { # First line, no compression. This sets the correct column width for all columns my $realcol = mapColor($elem); print ''; } else { if($firstelem) { $color = $elem; $width = 1; $firstelem = 0; } else { if($color eq $elem) { $width++; $saved++; } else { my $realcol = mapColor($color); print ''; $color = $elem; $width = 1; } } } } if(!$firstline) { # print last element of the current line my $realcol = mapColor($color); print ''; } print "\n"; $firstline = 0; } print '
', "\n"; print '', "\n"; sub mapColor { my ($inval) = @_; if($inval eq '*') { return 'black'; } return 'white'; } #### #!/usr/bin/env perl use strict; use warnings; use GD; my $img = GD::Image->newFromPng('tentacle.png', 0); my ($w, $h) = $img->getBounds(); my $pixelsize = 15; print '', "\n"; my $saved = 0; for(my $y = 0; $y < $h; $y++) { print ""; my $firstelem = 1; my $width = 0; my $color = ''; my $firstblockinline = 1; for(my $x = 0; $x < $w; $x++) { my $index = $img->getPixel($x, $y); my ($r,$g,$b) = $img->rgb($index); my $elem = sprintf("#%02X%02X%02X", $r, $g, $b); if(!$y) { # First line, no compression. This sets the correct column width for all columns print ''; } else { if($firstelem) { $color = $elem; $width = 1; $firstelem = 0; } else { if($color eq $elem) { $width++; $saved++; } else { print ''; $color = $elem; $width = 1; } } } } if($y) { # print last element of the current line print ''; } print "\n"; } print '
', "\n"; print '', "\n";