in reply to Re: Shameless plug and QR japh
in thread Shameless plug and QR japh
After thinking about the problem a bit, you could, in theory, use "colspan" for a simplistic run-length compression:
#!/usr/bin/env perl use strict; use warnings; use Text::QRCode; my $qr = Text::QRCode->new()->plot("YAPH"); my $pixelsize = 15; my $black = '<td width="' . $pixelsize . 'px" height="' . $pixelsize . + 'px" bgcolor="black"></td>'; my $white = '<td width="' . $pixelsize . 'px" height="' . $pixelsize . + 'px" bgcolor="white"></td>'; print '<table border="0">', "\n"; my $firstline = 1; my $saved = 0; foreach my $line (@{$qr}) { print "<tr>"; my $firstelem = 1; my $width = 0; my $color = ''; foreach my $elem (@{$line}) { if($firstline) { # First line, no compression. This sets the correct column + width for all columns if($elem eq '*') { print $black; } else { print $white; } } else { if($firstelem) { $color = $elem; $width = 1; $firstelem = 0; } else { if($color eq $elem) { $width++; $saved++; } else { my $realcol = 'white'; if($elem eq '*') { $realcol = 'black'; } print '<td colspan="' . $width . '" height="' . $p +ixelsize . 'px" bgcolor="' . $realcol . '"></td>'; $color = $elem; $width = 1; } } } if(!$firstline) { # print last element of the current line my $realcol = 'white'; if($elem eq '*') { $realcol = 'black'; } print '<td colspan="' . $width . '" height="' . $pixelsize + . 'px" bgcolor="' . $realcol . '"></td>'; } $firstline = 0; } print "</tr>\n"; } print '<\table">', "\n"; print '<!-- run length compression saved ', $saved, ' table fields-->' +, "\n";
I've run into a formatting problem doing this (probably some stupid oversight on my part), but it might be worth the effort if you need to "compress" your code to the 64K limit in PerlMonks. See What is PerlMonks post size limit?
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: Shameless plug and QR japh
by cavac (Prior) on Apr 08, 2022 at 13:19 UTC |