2005/11/16(水) [n年前の日記]
#3 [cg_tools] 数字の書かれた画像を大量に生成
数字の書かれた画像が欲しかったので、
_:: Cepheid :: - PerlMagickリファレンス
と
_PerlMagick + CGI
のページを参考に、Perlスクリプトを作成。
要するに、
こういう画像から、


こういう画像を作る。
#!/usr/bin/perl
# Last updated: <2005/11/16 15:57:04 +0900>
#
# 100 x 2 枚の数値が書かれた画像を作る
# PerlMagick(ImageMagick)を使用
use strict;
use Image::Magick;
for ( my $i=0; $i<=100; $i++ ) {
my $str = sprintf("%03d",$i);
my $text = $str;
my $fname_omote = "./".$str.'a.png';
my $fname_ura = "./".$str.'b.png';
my $basefile = 't' . ($i % 3) . '.tif'; # 't1.tif' etc
my $image = Image::Magick->new;
$image->Set(size=>'120x120');
$image->Read($basefile);
# $image->ReadImage('xc:white');
# $image->AddNoise('Impulse');
# $image->Blur(radius=>5, sigma=>0.5);
$image->Annotate(font=>'impact.ttf', pointsize=>48, stroke=>'white', strokewidth=>2, fill=>'black', antialias=>'true', text=>$text, gravity=>'Center');
$image->Write($fname_omote);
# $image->Colorize(fill=>'olive', opacity=>'128');
$image->Negate();
$image->Write($fname_ura);
undef $image;
print "make $fname_omote, $fname_ura\n";
}
exit;
t0.tif 〜 t2.tif を読み込んで、それら画像の上に順々に数字を書き込んで、別画像として出力。スクリプトのあるディレクトリに、利用するフォントファイル(.ttf) をコピーしてから使う。要するに、



[ ツッコむ ]
以上です。