Created
November 30, 2010 10:13
-
-
Save yusukebe/721457 to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
use LWP::UserAgent; | |
use Imager; | |
use Imager::QRCode; | |
use JSON qw/decode_json/; | |
my $username = $ARGV[0] || 'yusuke.wada'; | |
my $ua = LWP::UserAgent->new; | |
my $user; | |
{ | |
my $url = "https://graph.facebook.com/$username/picture"; | |
my $res = $ua->get($url); | |
die $res->status_line if $res->is_error; | |
$user->{picture} = $res->content; | |
} | |
{ | |
my $url = "https://graph.facebook.com/$username"; | |
my $res = $ua->get($url); | |
die $res->status_line if $res->is_error; | |
$user->{data} = decode_json( $res->content ); | |
} | |
my $img = Imager->new(); | |
$img->read( file => 'template.jpg' ) or die $img->errstr; | |
$img = $img->rubthrough( | |
src => do { | |
my $tmp = Imager->new; | |
$tmp->read( data => $user->{picture}, type => 'jpeg' ) | |
or die $tmp->errstr; | |
$tmp = $tmp->scale( xpixels => 100, ypixels => 100 ) | |
or die $tmp->errstr; | |
$tmp; | |
}, | |
tx => 40, | |
ty => 70, | |
) or die $img->errstr; | |
my $font = Imager::Font->new( file => 'ipagp.ttf' ); | |
$img->string( | |
x => 160, | |
y => 130, | |
string => $user->{data}->{name}, | |
font => $font, | |
size => 40, | |
aa => 1, | |
color => 'black', | |
) or die $img->errstr; | |
$img->string( | |
x => 40, | |
y => 200, | |
string => $user->{data}->{link}, | |
font => $font, | |
size => 20, | |
aa => 1, | |
color => 'black', | |
) or die $img->errstr; | |
my $qrcode = Imager::QRCode->new( | |
size => 3, | |
margin => 2, | |
version => 1, | |
level => 'M', | |
casesensitive => 1, | |
lightcolor => Imager::Color->new( 255, 255, 255 ), | |
darkcolor => Imager::Color->new( 0, 0, 0 ), | |
); | |
my $qr = $qrcode->plot( $user->{data}->{link} ); | |
$img = $img->paste( left => 20, top => 20, src => $qr ); | |
$img->write( file => 'out.jpg' ) or die $img->errstr; | |
use YAML; | |
warn Dump $user->{data}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment