Created
April 29, 2011 06:44
-
-
Save hiroyukim/947954 to your computer and use it in GitHub Desktop.
ローカル環境で外に出したくないデータをqrcodeにしたくなったときにはこんなんでいけるはず。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use Plack::Request; | |
use Imager::QRCode; | |
my $html = q{ | |
<html> | |
<head> | |
<title>qrcode</title> | |
</head> | |
<body> | |
<form method="POST" action="/"> | |
<input type="text" name="text" /> | |
<input type="submit" value="create" /> | |
</form> | |
</body> | |
</html> | |
}; | |
my $qrcode_file_path = "/tmp/qrcode.gif"; | |
my $app = sub { | |
my $env = shift; | |
my $req = Plack::Request->new($env); | |
if( $req->method eq 'POST' && $req->param('text') ) { | |
my $qrcode = Imager::QRCode->new( | |
size => 10, | |
margin => 2, | |
version => 1, | |
level => 'M', | |
casesensitive => 1, | |
lightcolor => Imager::Color->new(255, 255, 255), | |
darkcolor => Imager::Color->new(0, 0, 0), | |
); | |
my $img = $qrcode->plot($req->param('text')); | |
$img->write(file => $qrcode_file_path ) or die $img->errstr; | |
open my $fh_qrcode , '<', $qrcode_file_path or die $!; | |
my $qrcode_file = do { local $/; <$fh_qrcode> }; | |
close $fh_qrcode; | |
return [200,['Content-Type' => 'image/gif'],[$qrcode_file]]; | |
} | |
else { | |
return [200,['Content-Type' => 'text/html'],[$html]]; | |
} | |
}; |
open -a firefox http://localhost:5000/ でmacは開けるようだから、
vi qrcode_maker.sh
! /bin/sh
open -a firefox http://localhost:5000/
とかして pathに置いてあげればいいか。
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
macの場合、Imagerをinstallまえにhttp://sourceforge.net/projects/giflib/とかいれないとハマるけど。