# 複数画像からアニメーションgifを生成。 # use strict; use Image::Magick; use utf8; use Encode::Guess qw/shift-jis euc-jp 7bit-jis/; use Encode qw(from_to encode decode is_utf8 encode_utf8); # ------------------------------------------------- opendir(DRC,".");@gazou = grep(/\.(gif|jpg|png)/i,readdir(DRC));closedir(DRC); foreach $gazou (@gazou) { next if $gazou =~ m#_anbi\.gif#; print "gazou[$gazou]\n";# ; my $img_ORG = Image::Magick->new; $img_ORG->Read($gazou); my $w = $img_ORG->Get('width'); my $h = $img_ORG->Get('height'); print "w:h[$w:$h]\n";#; # 原図の作成 ------------------------------------------- my $size = ($w * 2) . "x" . ($h * 2); my $img_NEW = Image::Magick->new; $img_NEW->Set(size=>"$size"); $img_NEW->ReadImage('canvas:rgb(255, 255, 255)'); # 白 # 画像貼り付け ------------------------------------ $img = Image::Magick->new;$img->Read($gazou);'そのまま' ; $img_NEW->Composite(image=>$img,compose => 'over', x => 0 ,y => 0); $img = Image::Magick->new;$img->Read($gazou);'反転左右' ;$img->Flop; $img_NEW->Composite(image=>$img,compose => 'over', x => $w ,y => 0); $img = Image::Magick->new;$img->Read($gazou);'反転上下' ;$img->Flip; $img_NEW->Composite(image=>$img,compose => 'over', x => 0 ,y => $h); $img = Image::Magick->new;$img->Read($gazou);'回転180°';$img->Rotate(degrees=> 180);$img_NEW->Composite(image=>$img,compose => 'over', x => $w ,y => $h); $f_ou = $gazou; if ($f_ou =~ m#\.jpg#i) {$f_ou =~ s#\.jpg#__anbi.gif#i;} elsif ($f_ou =~ m#\.png#i) {$f_ou =~ s#\.png#__anbi.gif#i;} elsif ($f_ou =~ m#\.gif#i) {$f_ou =~ s#\.gif#__anbi.gif#i;} # 文字記入------------------------------------ if($h < 500){$pointsize = 24;$word_y = 20;} else {$pointsize = 72;$word_y = 70;} $wx = 20;$wy = $word_y ;&annotate($img_NEW,"元画像「ORIGIN」",$wx,$wy); $wx = $w + 20;$wy = $word_y ;&annotate($img_NEW,"鏡 「MIRRORL」",$wx,$wy); $wx = 20;$wy = ($h * 2) - 5;&annotate($img_NEW,"上下反転「FLOP」",$wx,$wy); $wx = $w + 20;$wy = ($h * 2) - 5;&annotate($img_NEW,"回転 「ROTATE」",$wx,$wy); # 線の記入 ------------------------------------ $point = "0,$h " . $w * 2 . ",$h"; $img_NEW->Draw(primitive=>'line', points=> $point , stroke=> "#ff0000", strokewidth=> 5); $point = "$w,0 $w," . $h * 2; $img_NEW->Draw(primitive=>'line', points=> $point , stroke=> "#ff0000", strokewidth=> 5); $img_NEW->Write("gif:$f_ou"); # 書き出し print "f_ou[$f_ou]\n";#; } print "all[end]";; # sub ---------------------------------------------------------------- sub annotate { my ($img_NEW,$moji,$x,$y) = @_; $img_NEW->Annotate( text => $moji, x => $x, #文字列のx 位置 y => $y, #文字列のy 位置 fill => "#FF0000", #文字の色 strokewidth => 2, #文字の太さ antialias => true, #アンチエイリアス pointsize => $pointsize, #文字サイズ # font => 'C:/Windows/Fonts/meiryo.ttc', font => 'C:/Windows/Fonts/msmincho.ttc', ); }