From 23e7bcb9b266904d5731dbe6e3794bc039f52ceb Mon Sep 17 00:00:00 2001 From: dakkar Date: Mon, 28 Mar 2011 21:39:41 +0100 Subject: cmdline opts, external data --- data/mecard | 1 + data/words | 135 ++++++++++++++++++++++++++++++++++++++++ script/qr-color.pl | 179 ++++++++++------------------------------------------- 3 files changed, 168 insertions(+), 147 deletions(-) create mode 100644 data/mecard create mode 100644 data/words diff --git a/data/mecard b/data/mecard new file mode 100644 index 0000000..f9f807e --- /dev/null +++ b/data/mecard @@ -0,0 +1 @@ +MECARD:N:Ceccarelli,Gianni;TEL:+447564023056;EMAIL:dakkar@thenautilus.net;URL:http://www.thenautilus.net/contacts/;NICKNAME:dakkar;; \ No newline at end of file diff --git a/data/words b/data/words new file mode 100644 index 0000000..46a8ce7 --- /dev/null +++ b/data/words @@ -0,0 +1,135 @@ +Richard Dawkins +Bruce Schneier +Lois McMaster Bujold +Kage Baker +David Weber +Robert Heinlein +Douglas Adams +Neal Stephenson +Lewis Carrol +Terry Pratchett +Jorge Luis Borges +Olaf Stapledon +Frank Herbert +Alessandro Bergonzoni +Stefano Benni +Jules Verne +Neil Gaiman +H.G. Wells +Isaac Asimov +Arthur C. Clarke +Philip K. Dick +JRR Tolkien +Ed Wood +Tim Burton +Monty Python +Terry Gilliam +Orson Welles +Luc Besson +Peter Greenaway +David Cronenberg +Stanley Kubrick +Joss Whedon +Quentin Tarantino +Pedro Almodóvar +Mel Brooks +宮崎駿 +MIYAZAKI Hayao +押井守 +OSHII Mamoru +庵野 秀明 +ANNO Hideaki +Alan Moore +鬼頭 莫宏 +KITOH Mohiro +手塚 治虫 +TEZUKA Osamu +ゆうきまさみ +YUKI Masami +浦沢 直樹 +URASAWA Naoki +星野 之宣 +YUKINOBU Hoshino +安倍 吉俊 +yoshitoshi ABe +士郎 正宗 +SHIROW Masamune +Amanda Palmer +Marian Call +Jonathan Coulton +The Flaming Lips +The Pillows +Nightwish +Stefano Nosei +Jethro Tull +菅野 よう子 +KANNO Yoko +Franco Battiato +Enya +Helloween +Mike Oldfield +Alan Parsons Project +Emerson, Lake & Palmer +Fabrizio De André +川井 憲次 +KAWAI Kenji +David Bowie +Girl Genius +Gunnerkrigg Court +Cyrano de Bergerac +Watership Down +RHPS +Thunderbirds +Doctor Who +The Twilight Zone +Blade Runner +Forbidden Planet +Cowboy Bebop +フリクリ +FLCL +Gundam +Macross +ふしぎの海のナディア +The Secret of Blue Water +涼みやはるひの消失 +SUZUMIYA Haruhi +Cutey Honey +電脳コイル +Dennou Coil +灰羽連盟 +Haibane Renmei +Star Trek +D&D +Go +Shogi +Perl +Firefly +トップをねらえ! +Gunbuster +Sandman +Honor Harrington +日本語 +Tiffany Aching +Dune +Snow Crash +HHGTTG +Dirk Gently +Halo Jones +Top 10 +Promethea +Blade Runner +The Princess Bride +The Blues Brothers +Groucho Marx +平成狸合戦ぽんぽこ +Pon Poko +となりのトトロ +Totoro +風の谷のナウシカ +Nausicaä +攻殻機動隊 +Ghost in the Shell +新世紀エヴァンゲリオン +Evangelion +Powerpuff Girls +Dresden Codak diff --git a/script/qr-color.pl b/script/qr-color.pl index 5942fca..134c887 100644 --- a/script/qr-color.pl +++ b/script/qr-color.pl @@ -8,6 +8,8 @@ use GridFiller::Result::Pango; use feature 'say'; use open ':std',':locale'; use Log::Log4perl qw(:easy); +use Getopt::Long; + Log::Log4perl->easy_init($INFO); #Log::Log4perl->get_logger('GridFiller')->level($INFO); @@ -15,13 +17,35 @@ Log::Log4perl->easy_init($INFO); #Log::Log4perl->get_logger('GridFiller::Status')->level($DEBUG); #Log::Log4perl->get_logger('GridFiller::Result')->level($DEBUG); -binmode DATA,':utf8'; +my ($data_file,$words_file,$level,$size,$output_file,$font_descr) + =(undef,undef,'M',40,'/tmp/qr.png',undef); +{ +my $p = Getopt::Long::Parser->new( + config => [qw( + no_auto_abbrev + no_getopt_compat + no_gnu_compat + require_order + no_ignore_case + )], +); +die unless $p->getoptions( + 'd|data=s' => \$data_file, + 'w|words=s' => \$words_file, + 'l|level=s' => \$level, + 's|size=i' => \$size, + 'o|output=s' => \$output_file, + 'f|font=s' => \$font_descr, +); +} -my $data = do { local $/="\n__WORDS__\n";my $x=;chomp $x;$x }; -my @words = ;chomp @words; +$level='M' unless $level=~m{^[LMH]$}i; + +my $data = do {open my $fh,'<:utf8',$data_file;local $/;<$fh>}; +my @words = do {open my $fh,'<:utf8',$words_file;<$fh>};chomp @words; my $qr=Text::QRCode->new( - level=>'H', + level=>uc($level), mode=>'8-bit', ); @@ -33,9 +57,9 @@ my $filler=GridFiller->new({ }); my $result = GridFiller::Result::Pango->new({ - source_grid => $filler->grid, - cell_size => 40, - ( @ARGV ? (font_description => $ARGV[0]) : () ), + source_grid => $arr, + cell_size => $size, + ( $font_descr ? (font_description => $font_descr) : () ), }); $filler->result($result); @@ -44,147 +68,8 @@ $filler->status->length($result->length_closure); $filler->fill(); -$result->save_png('/tmp/qr.png'); +$result->save_png($output_file); say ''; say 'Leftovers:'; say for @{$result->leftover_words}; - -__DATA__ -MECARD:N:Ceccarelli,Gianni;TEL:+447564023056;EMAIL:dakkar@thenautilus.net;URL:http://www.thenautilus.net/contacts/;NICKNAME:dakkar;; -__WORDS__ -Richard Dawkins -Bruce Schneier -Lois McMaster Bujold -Kage Baker -David Weber -Robert Heinlein -Douglas Adams -Neal Stephenson -Lewis Carrol -Terry Pratchett -Jorge Luis Borges -Olaf Stapledon -Frank Herbert -Alessandro Bergonzoni -Stefano Benni -Jules Verne -Neil Gaiman -H.G. Wells -Isaac Asimov -Arthur C. Clarke -Philip K. Dick -JRR Tolkien -Ed Wood -Tim Burton -Monty Python -Terry Gilliam -Orson Welles -Luc Besson -Peter Greenaway -David Cronenberg -Stanley Kubrick -Joss Whedon -Quentin Tarantino -Pedro Almodóvar -Mel Brooks -宮崎駿 -MIYAZAKI Hayao -押井守 -OSHII Mamoru -庵野 秀明 -ANNO Hideaki -Alan Moore -鬼頭 莫宏 -KITOH Mohiro -手塚 治虫 -TEZUKA Osamu -ゆうきまさみ -YUKI Masami -浦沢 直樹 -URASAWA Naoki -星野 之宣 -YUKINOBU Hoshino -安倍 吉俊 -yoshitoshi ABe -士郎 正宗 -SHIROW Masamune -Amanda Palmer -Marian Call -Jonathan Coulton -The Flaming Lips -The Pillows -Nightwish -Stefano Nosei -Jethro Tull -菅野 よう子 -KANNO Yoko -Franco Battiato -Enya -Helloween -Mike Oldfield -Alan Parsons Project -Emerson, Lake & Palmer -Fabrizio De André -川井 憲次 -KAWAI Kenji -David Bowie -Girl Genius -Gunnerkrigg Court -Cyrano de Bergerac -Watership Down -RHPS -Thunderbirds -Doctor Who -The Twilight Zone -Blade Runner -Forbidden Planet -Cowboy Bebop -フリクリ -FLCL -Gundam -Macross -ふしぎの海のナディア -The Secret of Blue Water -涼みやはるひの消失 -SUZUMIYA Haruhi -Cutey Honey -電脳コイル -Dennou Coil -灰羽連盟 -Haibane Renmei -Star Trek -D&D -Go -Shogi -Perl -Firefly -トップをねらえ! -Gunbuster -Sandman -Honor Harrington -日本語 -Tiffany Aching -Dune -Snow Crash -HHGTTG -Dirk Gently -Halo Jones -Top 10 -Promethea -Blade Runner -The Princess Bride -The Blues Brothers -Groucho Marx -平成狸合戦ぽんぽこ -Pon Poko -となりのトトロ -Totoro -風の谷のナウシカ -Nausicaä -攻殻機動隊 -Ghost in the Shell -新世紀エヴァンゲリオン -Evangelion -Powerpuff Girls -Dresden Codak -- cgit v1.2.3