Skip to content

Instantly share code, notes, and snippets.

@hiroyukim
Created April 29, 2011 06:44
Show Gist options
  • Save hiroyukim/947954 to your computer and use it in GitHub Desktop.
Save hiroyukim/947954 to your computer and use it in GitHub Desktop.
ローカル環境で外に出したくないデータをqrcodeにしたくなったときにはこんなんでいけるはず。
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]];
}
};
@hiroyukim
Copy link
Author

@hiroyukim
Copy link
Author

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