【perlメモ】CPANモジュール「GD::Barcode」を利用してQRコードを作成するサンプル

CPANモジュール「GD::Barcode」を使ってQRコードを生成するサンプル。実行環境はWindows XP Home上のActive perl 5.8.8

qr01.pl

#!/usr/bin/perl
use strict;
use warnings;
use GD::Barcode;

my $url = ‘https://blog.kumacchi.com/’;

my $qrimg = GD::Barcode->new(‘QRcode’,$url,{‘Ecc’=>’M’,Version=>’4′,’ModuleSize’=>’3′});

open(FILE,">qr.gif");
binmode(FILE);
print FILE $qrimg->plot->gif;
close(FILE);

exit(0);

実行:

F:\kumacchi\MyProgram\perl\sample\QRコード>qr01.pl

F:\kumacchi\MyProgram\perl\sample\QRコード>perl –v

上記のスクリプトを実行すると下のQRコードのgifファイルが生成される。

 qr

※$qrimg->plot->gif;を$qrimg->plot->png;とするとpngファイルでQRコードが生成される。

参考:

(Visited 640 times, 1 visits today)

タグ :