Contents ::
|
|
package k2;
;;;;;;;;;; use Jcode;
use Switch;
use Image::Magick;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;my ($IMG_IMAG0, $IMG_FLAG0, $IMG_IMAG1, $IMG_FLAG1, $IMG_IMAG2, $IMG_FLAG2);
sub imgLoad{
my ($fl) = @_;
return(0)unless(isExistsFile($fl));
imgFree();
$IMG_IMAG0 = Image::Magick->new;
$IMG_IMAG0->Read($fl);
$IMG_FLAG0 = 1;
return(1);
}
sub imgSave{
my ($fl, $cmp) = @_;
return(0)unless($IMG_FLAG0);
return(0)unless($fl);
if(ExtractFileExt($fl) eq 'jpg'){
$cmp = 85 unless($cmp);
$cmp = MinMax($cmp, 1, 100);
$IMG_IMAG0->Set(quality=>$cmp);
}
$IMG_IMAG0->Write($fl);
return(1);
}
sub imgCreate{
my ($wd, $ht, $cl) = @_;
return(0)if($wd.$ht eq '');
imgFree()if($IMG_FLAG0);
$IMG_IMAG0 = Image::Magick->new;
$IMG_IMAG0->Set(size=>$wd.'x'.$ht);
if(lc($cl) eq 't'){
$IMG_IMAG0->ReadImage('xc:transparent');
}else{
$cl = 'white'if($cl eq '');
$IMG_IMAG0->ReadImage("xc:$cl");
}
$IMG_FLAG0 = 1;
return(1);
}
sub imgOut{
my ($ext) = @_;
return(0)unless($IMG_FLAG0);
$ext = 'jpeg'if($ext eq 'jpg');
print "Content-type: image/$ext\n\n";
binmode STDOUT;
$IMG_IMAG0->Write("$ext:-");
}
sub imgFree{
return(0)unless($IMG_FLAG0);
undef($IMG_IMAG0);
$IMG_FLAG0 = 0;
return(1);
}
;;;sub imgInfoFl{
my ($fl) = @_;
return(0)unless(isExistsFile($fl));
my $img = Image::Magick->new;
$img->Read($fl);
my $wd = $img->Get('width');
my $ht = $img->Get('height');
my $ft = $img->Get('magick');
my $sz = $img->Get('filesize');
undef($img);
return($wd, $ht, $ft, $sz);
}
sub imgInfoI{
return(0)unless($IMG_FLAG0);
my $wd = $IMG_IMAG0->Get('width');
my $ht = $IMG_IMAG0->Get('height');
my $ft = $IMG_IMAG0->Get('magick');
my $sz = $IMG_IMAG0->Get('filesize');
return($wd, $ht, $ft, $sz);
}
sub imgPixel{
my ($x0, $y0) = @_;
return(0)unless($IMG_FLAG0);
my ($r, $g, $b, $ugh) = split(',', $IMG_IMAG0->Get("pixel[$x0,$y0]"));
foreach($r, $g, $b){$_ = int($_ / 256)};
my $col = rgb2color($r, $g, $b);
return($col);
}
sub imgRGB{
my ($x0, $y0) = @_;
return(0)unless($IMG_FLAG0);
my ($r, $g, $b, $ugh) = split(',', $IMG_IMAG0->Get("pixel[$x0,$y0]"));
foreach($r, $g, $b){$_ = int($_ / 256)};
return($r, $g, $b);
}
sub imgHSV{
my ($x0, $y0) = @_;
return(0)unless($IMG_FLAG0);
my ($r, $g, $b, $ugh) = split(',', $IMG_IMAG0->Get("pixel[$x0,$y0]"));
foreach($r, $g, $b){$_ = int($_ / 256)};
my ($h, $s, $v) = rgb2hsv($r, $g, $b);
return($h, $s, $v);
}
sub imgYUV{
my ($x0, $y0) = @_;
return(0)unless($IMG_FLAG0);
my ($r, $g, $b, $ugh) = split(',', $IMG_IMAG0->Get("pixel[$x0,$y0]"));
foreach($r, $g, $b){$_ = int($_ / 256)};
my ($h, $s, $v) = rgb2hsv($r, $g, $b);
return($h, $s, $v);
}
sub rgb2color{
my ($R, $G, $B) = @_;
my $col = '';
foreach($R, $G, $B){
$_ = unpack("H2", pack("C", $_));
$col .= "$_";
}
return($col);
}
sub color2rgb{
my($col) = @_;
my(@RGB, $i, $s);
$col = '000000'.$col;
$col = substr($col, length($col) - 6, 6);
for($i = 0; $i < 6; $i += 2){
$s = substr($col, $i, 2);
$RGB[@RGB] = hex($s);
}
return(@RGB);
}
sub rgb2yuv{
my ($R, $G, $B) = @_;
my ($Y, $U, $V);
$Y = 0.29891 * $R + 0.587 * $G + 0.114 * $B;
$U = -0.16874 * $R - 0.289 * $G + 0.436 * $B;
$V = 0.16874 * $R - 0.515 * $G - 0.100 * $B;
$Y = MinMax($Y, 0, 255);
$U = MinMax($U, 0, 255);
$V = MinMax($V, 0, 255);
return($Y, $U, $V);
}
sub rgb2hsv{
my ($R, $G, $B) = @_;
my ($H, $S, $V, $C, $max, $min);
if($R >= $G){
$max = $R;
}else{
$max = $G;
}
$max = $B if($B > $max);
if($R <= $G){
$min = $R;
}else{
$min = $G;
}
$min = $B if($B < $min);
$V = $max;
$C = $max - $min;
if($max == 0){
$S = 0;
}else{
$S = $C / $max;
}
if($S != 0){
if($R == $max){
$H = ($G - $B) / $C;
}else{
if($G == $max){
$H = 2 + ($B - $R) / $C;
}else{
$H = 4 + ($R - $G) / $C if($B == $max);
}
}
}
$H = $H * 60;
$H = $H + 360 if($H < 0);
$H = Round($H);
return($H, $S, $V);
}
sub hsv2rgb{
my ($H, $S, $V) = @_;
my ($R, $G, $B);
my ($d, $h, $f, $t1, $t2, $t3);
if($S < 0){$S = 0}
if($S > 1){$S = 1}
if($V < 0){$V = 0}
if($V > 1){$V = 1}
$h %= 360;
if($H < 0){$H += 360}
$H /= 60;
$d = Round($H);
$f = $H - $d;
$t1 = $V * (1 - $S);
$t2 = $V * (1 - $S * $f);
$t3 = $V * (1 - $S * (1 - $f));
if ($d == 0){$R = $V; $G = $t3; $B = $t1}
elsif($d == 1){$R = $t2; $G = $V; $B = $t1}
elsif($d == 2){$R = $t1; $G = $V; $B = $t3}
elsif($d == 3){$R = $t1; $G = $t2; $B = $V }
elsif($d == 4){$R = $t3; $G = $t1; $B = $V }
elsif($d == 5){$R = $V; $G = $t1; $B = $t2}
return($R, $G, $B);
}
=comment;
sub hsv2rgb1{
my ($H, $S, $V) = @_;
my ($R, $G, $B);
my ($ht, $d, $t1, $t2, $t3);
if($S == 0){
$R = $V;
$G = $V;
$B = $V;
}else{
$ht = $H * 6;
$d = $ht % 360;
$t1 = Round($V * (255 - $S) / 255);
$t2 = Round($V * (255 - $S * $d / 360) / 255);
$t3 = Round($V * (255 - $S * (360 - $d) / 360) / 255);
$ht %= 360;
if ($ht == 0){$R = $V; $G = $t3; $B = $t1}
elsif($ht == 1){$R = $t2; $G = $V; $B = $t1}
elsif($ht == 2){$R = $t1; $G = $V; $B = $t3}
elsif($ht == 3){$R = $t1; $G = $t2; $B = $V }
elsif($ht == 4){$R = $t3; $G = $t1; $B = $V }
elsif($ht == 5){$R = $V; $G = $t1; $B = $t2}
}
return($R, $G, $B);
}
sub rgb2hsv1{
my ($R, $G, $B) = @_;
my ($H, $S, $V, $C, $Rc, $Gc, $Bc, $max, $min);
$max = Max($R, Max($G, $B));
$min = Min($R, Min($G, $B));
$V = $max;
if($max != 0){
$S = ($max - $min * 255) / $max;
}else{
$S = 0;
}
if($S == 0){
$H = 0;
}else{
if($max != $min){
my $def = ($max - $min);
$Rc = ($max - $R) / $def;
$Gc = ($max - $G) / $def;
$Bc = ($max - $B) / $def;
if($R = $max){
$H = $Bc - $Gc;
}elsif($G == $max){
$H = 2 + $C - $Bc;
}else{
if($B == $max){
$H = 4 + $Gc - $Rc;
}
}
$H = $H * 60;
if($H < 0){
$H = $H + 360;
}
$H = Round($H);
}
}
return($H, $S, $V);
}
=cut;
;;;sub imgTrans{
return(0)unless($IMG_FLAG0);
$IMG_IMAG0->ReadImage('xc:transparent');
return(1);
}
sub imgDelNoize{
my ($vl) = @_;
return(0)unless($IMG_FLAG0);
$vl = '' if($vl eq '');
$IMG_IMAG0->ReduceNoise(radius=>$vl);
return(1);
}
;;;sub imgZoom{
my ($sw) = @_;
return(0)unless($IMG_FLAG0);
unless($sw){
$IMG_IMAG0->Minify();
}else{
$IMG_IMAG0->Magnify();
}
return(1);
}
sub imgResize{
my ($wd, $ht, $bl) = @_;
return(0)unless($IMG_FLAG0);
return(0)unless($wd);
if($wd){
unless($ht){
$IMG_IMAG0->Scale(geometry=>$wd);
}else{
$bl = 'none'unless($bl);
$IMG_IMAG0->Resize(width=>$wd, height=>$ht, blur=>$bl);
}
}
return(1);
}
sub imgRotate{
my ($ag, $bg) = @_;
return(0)unless($IMG_FLAG0);
return(0)unless($ag);
$bg = 'white' if($bg eq '');
$IMG_IMAG0->Rotate(degrees=>$ag, color=>$bg);
return(1);
}
sub imgRoll{
my ($x0, $y0) = @_;
return(0)unless($IMG_FLAG0);
$x0 = '1' if($x0 eq '');
$y0 = '1' if($y0 eq '');
$IMG_IMAG0->Roll(x=>$x0, y=>$y0);
return(1);
}
;;;sub imgTile{
my ($fl, $xn, $yn) = @_;
return(0)unless($IMG_FLAG0);
return(0)unless(isExistsFile($fl));
my $img = Image::Magick->new;
$img->Read($fl);
$xn = 2 if($xn == 0);
$xn = 2 if($xn eq '');
my $wd = $IMG_IMAG0->Get('width');
my $ht = $IMG_IMAG0->Get('height');
if($yn eq ''){
$wd = int($wd / $xn);
$img->Scale(geometry=>$wd);
}else{
$wd = int($wd / $xn);
$ht = int($ht / $yn);
$img->Resize(width=>$wd, height=>$ht, blur=>0.7);
}
$IMG_IMAG0->Composite(image=>$img, compose=>'over', tile=>'true');
undef($img);
return(1);
}
sub imgAppend{
my ($sw, $no, $fl, $bc) = @_;
return(0)unless($IMG_FLAG0);
$fl = 'self'if($fl eq 'me');
return(0)unless(isExistsFile($fl) || $fl eq 'self');
$sw = MinMax($sw, 0, 3);
$no = '1' unless($no);
$bc = 'white'if($bc eq '');
my $img = Image::Magick->new;
my ($w0, $h0, $w1, $h1, $wd, $ht, $wx, $wy);
if($fl eq 'self'){
$img = $IMG_IMAG0;
}else{
$img->Read($fl);
}
$w0 = $IMG_IMAG0->Get('width');
$h0 = $IMG_IMAG0->Get('height');
$w1 = $img->Get('width');
$h1 = $img->Get('height');
if($sw < 2){
$wx = $w1 * $no;
$wd = $w0 + $wx;
$ht = ($h0 > $h1) ? $h0 : $h1;
}else{
$wd = ($w0 > $w1) ? $w0 : $w1;
$wy = $h1 * $no;
$ht = $h0 + $wy;
}
my $im1 = Image::Magick->new;
my($x0, $y0, $x1, $y1, $vx, $vy);
$im1->Set(size=>$wd.'x'.$ht);
$im1->ReadImage("xc:$bc");
if ($sw == 0){$x0 = $wx; $vx = $w1}
elsif($sw == 1){$x1 = $w0; $vx = $w1}
elsif($sw == 2){$y0 = $wy; $vy = $h1}
elsif($sw == 3){$y1 = $h0; $vy = $h1}
$im1->Composite(image=>$IMG_IMAG0, compose=>'over', x=>$x0, y=>$y0);
for(1..$no){
$im1->Composite(image=>$img, compose=>'over', x=>$x1, y=>$y1);
$x1 += $vx;
$y1 += $vy;
}
$IMG_IMAG0 = $im1;
undef($im1);
undef($img);
return(1);
}
sub imgAniGif{
my ($lp, $tm, $fl, @gif) = @_;
my $img = Image::Magick->new;
foreach(@gif){
$img->Read($_);
}
$lp = 0 if($lp eq '');
$img->Set(delay=>$tm, loop=>$lp);
$img->Write($fl);
undef($img);
return(1);
}
;;;;sub imgChange{
return(0)unless($IMG_FLAG0);
return(0)unless($IMG_FLAG1);
my $img = $IMG_IMAG0;
$IMG_IMAG0 = $IMG_IMAG1;
$IMG_IMAG1 = $img;
}
sub imgCopy{
my ($x0, $y0, $wd, $ht) = @_;
return(0)unless($IMG_FLAG0);
if($IMG_IMAG1){
undef($IMG_IMAG1);
$IMG_FLAG1 = 0;
}
$IMG_IMAG1 = $IMG_IMAG0->Clone;
$IMG_FLAG1 = 1;
if($x0.$y0.$wd.$ht ne ''){
$x0 = '0' if($x0 eq '');
$y0 = '0' if($y0 eq '');
$wd = $IMG_IMAG1->Get('width') if($wd eq '');
$ht = $IMG_IMAG1->Get('height')if($ht eq '');
$IMG_IMAG1->Crop(width=>$wd, height=>$ht, x=>$x0, y=>$y0);
}
return(1);
}
sub imgCopy2{
my ($x0, $y0, $wd, $ht) = @_;
return(0)unless($IMG_FLAG0);
if($IMG_IMAG2){
undef($IMG_IMAG2);
$IMG_FLAG2 = 0;
}
$IMG_IMAG2 = $IMG_IMAG0->Clone;
$IMG_FLAG2 = 1;
if($x0.$y0.$wd.$ht ne ''){
$x0 = '0' if($x0 eq '');
$y0 = '0' if($y0 eq '');
$wd = $IMG_IMAG2->Get('width') if($wd eq '');
$ht = $IMG_IMAG2->Get('height')if($ht eq '');
$IMG_IMAG2->Crop(width=>$wd, height=>$ht, x=>$x0, y=>$y0);
}
return(1);
}
sub imgPast{
my ($sw, $tr, $x0, $y0, $wd, $ht) = @_;
my $ret = imgComposite('img1', 0, $sw, $tr, $x0, $y0, $wd, $ht);
return($ret);
}
sub imgPast2{
my ($sw, $tr, $x0, $y0, $wd, $ht);
my $ret = imgComposite('img2', 1, $sw, $tr, $x0, $y0, $wd, $ht);
return($ret);
}
sub imgPastF{
my ($fl, $sw, $tr, $x0, $y0, $wd, $ht) = @_;
return(0)unless(isExistsFile($fl));
my $ret = imgComposite($fl, 0, $sw, $tr, $x0, $y0, $wd, $ht);
return($ret);
}
sub imgTrim{
my ($x0, $y0, $wd, $ht) = @_;
return(0)unless($IMG_FLAG0);
if($x0.$y0.$wd.$ht eq ''){
$IMG_IMAG0->Trim();
}else{
return(0)unless($wd);
return(0)unless($ht);
$x0 = '0' if($x0 eq '');
$y0 = '0' if($y0 eq '');
$IMG_IMAG0->Crop(width=>$wd, height=>$ht, x=>$x0, y=>$y0);
}
return(1);
}
sub imgComposite{
my ($fl, $mf, $sw, $tr, $x0, $y0, $wd, $ht) = @_;
return(0)unless($IMG_FLAG0);
return(0)unless(isExistsFile($fl) || substr($fl, 0, 3) eq 'img');
my $img = Image::Magick->new;
if($fl eq 'img1'){
$img = $IMG_IMAG1->Clone;
undef($IMG_IMAG1);
$IMG_FLAG1 = 0;
}elsif($fl eq 'img2'){
$img = $IMG_IMAG2->Clone;
undef($IMG_IMAG2);
$IMG_FLAG2 = 0;
}else{
$img->Read($fl);
}
if($sw){
my $cl;
if($sw eq '1'){
my $h = $IMG_IMAG0->Get('height') - 1;
my ($r, $g, $b) = split(',', $img->Get("pixel[0,$h]"));
$cl = '#'.rgb2color($r, $g, $b);
}else{
$cl = $sw;
}
$img->Transparent(color=>$cl);
}
if($wd.$ht){
if($wd){
unless($ht){
$img->Scale(geometry=>$wd);
}else{
$img->Resize(width=>$wd, height=>$ht, blur=>0.7);
}
}
}
if($sw){
$IMG_IMAG0->Composite(
image=>$img,
compose=>'over',
x=>$x0,
y=>$y0
);
}else{
if($mf && $IMG_FLAG2){
$IMG_IMAG0->Composite(
image=>$IMG_IMAG2,
compose=>'over',
x=>$x0,
y=>$y0,
mask=>$img
);
undef($IMG_IMAG2);
$IMG_FLAG2 = 0;
}else{
$tr = '0'if($tr eq '');
$IMG_IMAG0->Composite(
image=>$img,
compose=>'over',
x=>$x0,
y=>$y0,
opacity=>"$tr%"
);
}
}
undef($img);
return(1);
}
;;;my ($IMG_FTNAM, $IMG_XPT00, $IMG_YPT00, $IMG_XPT01, $IMG_YPT01, $IMG_COLOR, $IMG_BKCOL, $IMG_PENWD, $IMG_ANTA0, $IMG_ANTA1, $IMG_ANTA2);
my ($IMG_STKWD, $IMG_WAITE, $IMG_ITLIC, $IMG_UDCOL, $IMG_ALIGN);
sub imgFont{
my ($fn) = @_;
$IMG_FTNAM = $fn;
}
sub imgXY{
my ($x0, $y0, $x1, $y1) = @_;
$IMG_XPT00 = $x0;
$IMG_YPT00 = $y0;
$IMG_XPT01 = $x1;
$IMG_YPT01 = $y1;
}
sub imgXY0{
my ($x0, $y0) = @_;
$IMG_XPT00 = $x0;
$IMG_YPT00 = $y0;
}
sub imgXY1{
my ($x1, $y1) = @_;
$IMG_XPT01 = $x1;
$IMG_YPT01 = $y1;
}
sub imgCol{
my ($cl) = @_;
$IMG_COLOR = $cl;
}
sub imgBcl{
my ($cl) = @_;
$IMG_BKCOL = $cl;
}
sub imgPen{
my ($pw) = @_;
$IMG_PENWD = $pw;
}
sub imgAnti{
my ($as) = @_;
$IMG_ANTA0 = $as;
}
sub imgAng0{
my ($ag) = @_;
$IMG_ANTA1 = $ag;
}
sub imgAng1{
my ($ag) = @_;
$IMG_ANTA2 = $ag;
}
;;;sub imgFill{
my ($cl, $bc, $x0, $y0) = @_;
return(0)unless($IMG_FLAG0);
my $bcl = $bc;
$cl = $IMG_COLOR if($cl eq '');
$bc = $IMG_BKCOL if($bc eq '');
$x0 = 0 if($x0 eq '');
$y0 = 0 if($y0 eq '');
return(0)if($cl eq '');
return(0)if($x0 eq '');
return(0)if($y0 eq '');
if($bc){
$IMG_IMAG0->ColorFloodfill(x=>$x0, y=>$y0, fill=>$cl, bordercolor=>$bc);
}else{
if($bcl eq '' && $x0 eq '0' && $y0 eq '0'){
my $wd = $IMG_IMAG0->Get('width');
my $ht = $IMG_IMAG0->Get('height');
imgRect(1, $cl, $cl, 0, 0, 0, 0, 0, 0, $wd, $ht);
}else{
$IMG_IMAG0->ColorFloodfill(x=>$x0, y=>$y0, fill=>$cl);
}
}
return(1);
}
sub imgColorA2B{
my ($cl, $bc) = @_;
return(0)unless($IMG_FLAG0);
return(0)if($cl eq '');
return(0)if($bc eq '');
$IMG_IMAG0->Opaque(color=>$cl, fill=>$bc);
return(1);
}
sub imgPoint{
my ($cl, $x0, $y0) = @_;
return(0)unless($IMG_FLAG0);
$cl = $IMG_COLOR if($cl eq '');
$x0 = $IMG_XPT00 if($x0 eq '');
$y0 = $IMG_YPT00 if($y0 eq '');
return(0)if($x0 eq '');
return(0)if($y0 eq '');
$cl = 'black'if($cl eq '');
$IMG_IMAG0->Draw(primitive=>'point', points=>"$x0,$y0", fill=>$cl);
return(1);
}
sub imgLine{
my ($cl, $pw, $as, $x0, $y0, $x1, $y1) = @_;
return(0)unless($IMG_FLAG0);
$cl = $IMG_COLOR if($cl eq '');
$pw = $IMG_PENWD if($pw eq '');
$as = $IMG_ANTA0 if($as eq '');
$x0 = $IMG_XPT00 if($x0 eq '');
$y0 = $IMG_YPT00 if($y0 eq '');
$x1 = $IMG_XPT01 if($x1 eq '');
$y1 = $IMG_YPT01 if($y1 eq '');
return(0)if($x0 eq '');
return(0)if($y0 eq '');
return(0)if($x1 eq '');
return(0)if($y1 eq '');
$cl = 'black' if($cl eq '');
$pw = '1' if($pw eq '');
$as = '0' if($as eq '');
$as = MinMax($as, 0, 1);
$as = ($as) ? 'true' : 'false';
$IMG_IMAG0->Draw(
primitive=>'line',
points=>"$x0,$y0 $x1,$y1",
strokewidth=>$pw,
stroke=>$cl,
antialias=>$as
);
return(1);
}
sub imgRect{
my ($pw, $cl, $bc, $ag, $as, $sx, $sy, $x0, $y0, $x1, $y1) = @_;
return(0)unless($IMG_FLAG0);
$pw = $IMG_PENWD if($pw eq '');
$cl = $IMG_COLOR if($cl eq '');
$bc = $IMG_BKCOL if($bc eq '');
$ag = $IMG_ANTA1 if($ag eq '');
$as = $IMG_ANTA0 if($as eq '');
$x0 = $IMG_XPT00 if($x0 eq '');
$y0 = $IMG_YPT00 if($y0 eq '');
$x1 = $IMG_XPT01 if($x1 eq '');
$y1 = $IMG_YPT01 if($y1 eq '');
return(0)if($x0 eq '');
return(0)if($y0 eq '');
return(0)if($x1 eq '');
return(0)if($y1 eq '');
$ag = '0' if($ag eq '');
$pw = '1' if($pw eq '');
$cl = 'black' if($cl eq '');
$bc = 'none' if($bc eq '');
$as = '0' if($as eq '');
$sx = 'none' if($sx eq '');
$sy = 'none' if($sy eq '');
$as = MinMax($as, 0, 1);
$as = ($as) ? 'true' : 'false';
$IMG_IMAG0->Draw(
primitive=>'rectangle',
points=>"$x0,$y0 $x1,$y1",
stroke=>$cl, fill=>$bc,
strokewidth=>$pw,
rotate=>$ag,
skewX=>$sx,
skewY=>$sy,
antialias=>$as
);
return(1);
}
sub imgRoundRect{
my ($pw, $cl, $bc, $rd, $as, $x0, $y0, $x1, $y1) = @_;
my @xy = (
[180, 270, $x0, $y0 + $rd, $x0 + $rd, $y0],
[-90, 0, $x1 - $rd, $y0, $x1, $y0 + $rd],
[ 0, 90, $x1, $y1 - $rd, $x1 - $rd, $y1],
[ 90, 180, $x0 + $rd, $y1, $x0, $y1 - $rd]
);
for(my $i = 0; $i < 4; $i++){
my ($a0, $a1, $x0, $y0, $x1, $y1) = @{$xy[$i]};
imgArc($a0, $a1, $pw, $cl, 'white', $as, $x0, $y0, $x1, $y1);
}
$rd -= $rd / 2;
imgLine($cl, $pw, $as, $x0 + $rd, $y0, $x1 - $rd, $y0);
imgLine($cl, $pw, $as, $x0 + $rd, $y1, $x1 - $rd, $y1);
imgLine($cl, $pw, $as, $x0, $y0 + $rd, $x0, $y1 - $rd);
imgLine($cl, $pw, $as, $x1, $y0 + $rd, $x1, $y1 - $rd);
if($bc){
imgFill($bc, $cl, ($x1 - $x0) / 2, ($y1 - $y0) / 2);
}
}
sub imgArc{
my ($a0, $a1, $pw, $cl, $bc, $as, $x0, $y0, $x1, $y1) = @_;
return(0)unless($IMG_FLAG0);
$a0 = $IMG_ANTA1 if($a0 eq '');
$a1 = $IMG_ANTA2 if($a1 eq '');
$pw = $IMG_PENWD if($pw eq '');
$cl = $IMG_COLOR if($cl eq '');
$bc = $IMG_BKCOL if($bc eq '');
$as = $IMG_ANTA0 if($as eq '');
$x0 = $IMG_XPT00 if($x0 eq '');
$y0 = $IMG_YPT00 if($y0 eq '');
$x1 = $IMG_XPT01 if($x1 eq '');
$y1 = $IMG_YPT01 if($y1 eq '');
return(0)if($a0 eq '');
return(0)if($a1 eq '');
return(0)if($x0 eq '');
return(0)if($y0 eq '');
return(0)if($x1 eq '');
return(0)if($y1 eq '');
$pw = '1' if($pw eq '');
$cl = 'black' if($cl eq '');
$bc = 'none' if($bc eq '');
$as = '0' if($as eq '');
$as = MinMax($as, 0, 1);
$as = ($as) ? 'true' : 'false';
$IMG_IMAG0->Draw(
primitive=>'arc',
points=>"$x0,$y0 $x1,$y1 $a0,$a1",
strokewidth=>$pw,
stroke=>$cl,
fill=>$bc,
antialias=>$as
);
return(1);
}
sub imgEllipse{
my ($pw, $cl, $bc, $a0, $a1, $as, $ox, $oy, $rx, $ry) = @_;
return(0)unless($IMG_FLAG0);
$ox = $IMG_XPT00 if($ox eq '');
$oy = $IMG_YPT00 if($oy eq '');
$rx = $IMG_XPT01 if($rx eq '');
$ry = $IMG_YPT01 if($ry eq '');
return(0)if($ox eq '');
return(0)if($oy eq '');
return(0)if($rx eq '');
return(0)if($ry eq '');
$pw = $IMG_PENWD if($pw eq '');
$cl = $IMG_COLOR if($cl eq '');
$bc = $IMG_BKCOL if($bc eq '');
$a0 = $IMG_ANTA1 if($a0 eq '');
$a1 = $IMG_ANTA2 if($a0 eq '');
$as = $IMG_ANTA0 if($as eq '');
$pw = '1' if($pw eq '');
$cl = 'black' if($cl eq '');
$bc = 'none' if($bc eq '');
$a0 = '0' if($a0 eq '');
$a1 = '359' if($a1 eq '');
$as = '0' if($as eq '');
$as = MinMax($as, 0, 1);
$as = ($as) ? 'true' : 'false';
$IMG_IMAG0->Draw(
primitive=>'ellipse',
points=>"$ox,$oy $rx,$ry $a0,$a1",
strokewidth=>$pw,
stroke=>$cl,
fill=>$bc,
antialias=>$as
);
return(1);
}
sub imgCircle{
my ($pw, $cl, $bc, $as, $ox, $oy, $px, $py) = @_;
return(0)unless($IMG_FLAG0);
$ox = $IMG_XPT00 if($ox eq '');
$oy = $IMG_YPT00 if($oy eq '');
$px = $IMG_XPT01 if($px eq '');
$py = $IMG_YPT01 if($py eq '');
return(0)if($ox eq '');
return(0)if($oy eq '');
return(0)if($px eq '');
return(0)if($py eq '');
$pw = $IMG_PENWD if($pw eq '');
$cl = $IMG_COLOR if($cl eq '');
$bc = $IMG_BKCOL if($bc eq '');
$as = $IMG_ANTA0 if($as eq '');
$pw = '1' unless($pw);
$cl = 'black' unless($cl);
$bc = 'none' if($bc eq '');
$as = '0' if($as eq '');
$as = MinMax($as, 0, 1);
$as = ($as) ? 'true' : 'false';
$IMG_IMAG0->Draw(
primitive=>'circle',
points=>"$ox,$oy $px,$py",
strokewidth=>$pw,
stroke=>$cl,
fill=>$bc,
antialias=>$as
);
return(1);
}
sub imgPolygon{
my ($sw, $cl, $bc, $pw, $as, @xy) = @_;
return(0)unless($IMG_FLAG0);
return(0)unless(@xy);
$sw = '0' if($sw eq '');
$cl = $IMG_COLOR if($cl eq '');
$bc = $IMG_BKCOL if($bc eq '');
$pw = $IMG_PENWD if($pw eq '');
$as = $IMG_ANTA0 if($as eq '');
$cl = 'black' if($cl eq '');
$bc = 'none' if($bc eq '');
$pw = '1' if($pw eq '');
$as = '0' if($as eq '');
my $pl;
$sw = MinMax($sw, 0, 3);
if($sw == 0){@xy = SplineCrv(8, @xy)}
if($sw == 1){@xy = BezierCrv(100, @xy)}
for(my $i = 0; $i < @xy; $i++){
$pl .= $xy[$i][0].','.$xy[$i][1].' ';
}
if($sw <= 2){
$sw = 'polyline';
$bc = 'none';
}else{
$sw = 'polygon';
}
$as = MinMax($as, 0, 1);
$as = ($as) ? 'true' : 'false';
$IMG_IMAG0->Draw(
primitive=>$sw,
points=>$pl,
strokewidth=>$pw,
stroke=>$cl,
fill=>$bc,
antialias=>$as
);
return(1);
}
sub imgText{
my ($ch, $fs, $fc, $bc, $fn, $ag, $as, $x0, $y0) = @_;
return(0)unless($IMG_IMAG0);
$fc = $IMG_COLOR if($fc eq '');
$bc = $IMG_BKCOL if($bc eq '');
$fn = $IMG_FTNAM if($fn eq '');
$ag = $IMG_ANTA1 if($ag eq '');
$as = $IMG_ANTA0 if($as eq '');
return(0)unless($fn);
return(0)if($ch eq '');
return(0)unless(-e $fn);
$fs = 24 if($fs eq '');
$fc = 'none' if($fc eq '');
$bc = 'none' if($bc eq '');
$as = '0' if($as eq '');
$ag = '0' if($ag eq '');
$as = MinMax($as, 0, 1);
$as = ($as) ?'true' : 'false';
my @al = (
'NorthWest', 'North' , 'NorthEast',
'West' , 'Center', 'East' ,
'SouthWest', 'South' , 'SouthEast'
);
my $grv;
if($x0 ne '' && $y0 eq ''){
my $i = MinMax($x0, 0, 8);
$grv = $al[$i];
$x0 = 0;
$y0 = 0;
}else{
$grv = $al[0];
$x0 = $IMG_XPT00 if($x0 eq '');
$y0 = $IMG_YPT00 if($y0 eq '');
$x0 = 0 if($x0 eq '');
$y0 = 0 if($y0 eq '');
}
$ch = cnv2utf($ch)if(isKanji($ch, 2));
$IMG_STKWD = 1 unless($IMG_STKWD);
$IMG_WAITE = 0 if($IMG_WAITE eq '');
$IMG_UDCOL = 'none' if($IMG_UDCOL eq '');
$IMG_ITLIC = 'Normal' if($IMG_ITLIC eq '');
unless($IMG_ALIGN){
$IMG_IMAG0->Annotate(
text=>$ch,
font=>$fn,
fill=>$fc,
stroke=>$bc,
strokewidth=>$IMG_STKWD,
undercolor=>$IMG_UDCOL,
pointsize=>$fs,
weight=>$IMG_WAITE, style=>$IMG_ITLIC, x=>$x0,
y=>$y0,
rotate=>$ag,
gravity=>$grv,
antialias=>$as,
encoding=>'UTF-8'
);
}else{
my @av = ('Left', 'Center', 'Right');
$IMG_ALIGN = MinMax($IMG_ALIGN, 0, 2);
$IMG_IMAG0->Annotate(
text=>$ch,
font=>$fn,
fill=>$fc,
stroke=>$bc,
strokewidth=>$IMG_STKWD,
undercolor=>$IMG_UDCOL,
pointsize=>$fs,
weight=>$IMG_WAITE,
style=>$IMG_ITLIC,
align=>$IMG_ALIGN,
x=>$x0,
y=>$y0,
rotate=>$ag,
gravity=>$grv,
antialias=>$as,
encoding=>'UTF-8'
);
}
$IMG_WAITE = '';
$IMG_UDCOL = '';
$IMG_ALIGN = '';
$IMG_STKWD = '';
$IMG_ITLIC = '';
return(1);
}
sub imgGradationText{
my ($ch, $fs, $dr, $tm, $c0, $c1, $bd, $fn, $ag, $as, $x0, $y0) = @_;
return(0)unless($IMG_IMAG0);
imgCopy();
imgFill('black');
$bd = ($bd) ? 'white' : '';
my ($wd, $ht) = imgInfoI();
if(imgText($ch, $fs, 'white', $bd, $fn, $ag, $as, 0, 0)){
my $mask = Image::Magick->new;
my $comp = Image::Magick->new;
my $grad = Image::Magick->new;
imgTrim();
my ($gw, $gh) = imgInfoI();
$mask->Set(size=>$gw."x".$gh);
$mask->ReadImage('xc:black');
$mask->Composite(
image=>$IMG_IMAG0,
compose=>'over',
x=>0,
y=>0,
);
$comp->Set(size=>$gw."x".$gh);
$comp->ReadImage('xc:transparent');
unless($dr){
$grad->Set(size=>$gw.'x'.$gh);
$grad->ReadImage("gradient:$c0-$c1");
}else{
$grad->Set(size=>$gh.'x'.$gw);
$grad->ReadImage("gradient:$c0-$c1");
$grad->Rotate(degrees=>-90);
}
$comp->Composite(
image=>$grad,
compose=>'over',
x=>0,
y=>0,
mask=>$mask
);
unless($tm){
imgResize($wd, $ht);
imgPast();
if($y0 eq ''){
if($x0 == 0){$x0 = 0; $y0 = 0}
if($x0 == 1){$x0 = ($wd - $gw) / 2; $y0 = 0}
if($x0 == 2){$x0 = $wd - $gw; $y0 = 0}
if($x0 == 3){$x0 = 0; $y0 = ($ht - $gh) / 2}
if($x0 == 4){$x0 = ($wd - $gw) / 2; $y0 = ($ht - $gh) / 2}
if($x0 == 5){$x0 = $wd - $gw; $y0 = ($ht - $gh) / 2}
if($x0 == 6){$x0 = 0; $y0 = $ht - $gh}
if($x0 == 7){$x0 = ($wd - $gw) / 2; $y0 = $ht - $gh}
if($x0 == 8){$x0 = $wd - $gw; $y0 = $ht - $gh}
}
}else{
imgPast();
}
$IMG_IMAG0->Composite(
image=>$comp,
compose=>'over',
x=>$x0,
y=>$y0
);
undef($grad);
undef($comp);
undef($mask);
return(1);
}else{
unless($tm){imgPast()};
return(0);
}
}
sub imgFont1{
my ($bw, $bg, $al) = @_;
$IMG_UDCOL = ($bg) ? $bg : 'none';
$IMG_STKWD = $bw;
$IMG_ALIGN = $al;
}
;;;;sub SplineCvt{
my ($mu1, $p0, $p1, $p2, $p3) = @_;
my ($mu2, $mu3, $ret);
$mu2 = $mu1 * $mu1;
$mu3 = $mu2 * $mu1;
$ret = Round((1 / 6) * (
$mu3 * (-$p0 + 3 * $p1 -3 * $p2 + $p3) +
$mu2 * (3 * $p0 - 6 * $p1 + 3 * $p2) +
$mu1 * (-3 * $p0 + 3 * $p2) + ($p0 + 4 * $p1 + $p2))
);
return($ret);
}
sub SplineCrv{
my ($seg, @pt) = @_;
my $max = $#pt;
return(@pt)if($max < 3);
my $mudelta = 1 / $seg;
my $NumPoints = MinMax($max + 2, 4, 16383);
push(@pt, $pt[$max]);
unshift(@pt, $pt[0]);
my $ct =-1;
my (@xy, $mu, $x, $y);
for(my $n = 3; $n <= $NumPoints; $n++){
$mu =0;
$x = SplineCvt($mu, $pt[$n-3][0], $pt[$n-2][0], $pt[$n-1][0], $pt[$n][0]);
$y = SplineCvt($mu, $pt[$n-3][1], $pt[$n-2][1], $pt[$n-1][1], $pt[$n][1]);
$mu = $mu + $mudelta;
$ct++;
$xy[$ct][0] = $x;
$xy[$ct][1] = $y;
for(my $h = 1; $h <= $seg; $h++){
$x = SplineCvt($mu, $pt[$n-3][0], $pt[$n-2][0], $pt[$n-1][0], $pt[$n][0]);
$y = SplineCvt($mu, $pt[$n-3][1], $pt[$n-2][1], $pt[$n-1][1], $pt[$n][1]);
$ct++;
$xy[$ct][0] = $x;
$xy[$ct][1] = $y;
$mu = $mu + $mudelta;
}
}
return(@xy);
}
;;;;sub BezierCvt{
my (@pt) = @_;
my ($prx, $pry, $p0x, $p0y, $p1x, $p1y, $p2x, $p2y) = (
$pt[0][0], $pt[0][1],
$pt[1][0], $pt[1][1],
$pt[2][0], $pt[2][1],
$pt[3][0], $pt[3][1]
);
my ($dx, $dy, $k, $r, $b);
my ($x1, $y1, $x2, $y2, $x3, $y3, $x4, $y4);
$k = 0.3;
$x1 = $p0x;
$y1 = $p0y;
$x4 = $p1x;
$y4 = $p1y;
$dx = $x4 - $x1;
$dy = $y4 - $y1;
$r = $k * sqrt($dx * $dx + $dy * $dy);
$dx = $p1x - $prx;
$dy = $p1y - $pry;
$b = sqrt($dx * $dx + $dy * $dy);
$x2 = $x1 + $r * $dx / $b;
$y2 = $y1 + $r * $dy / $b;
$dx = $p0x - $p2x;
$dy = $p0y - $p2y;
$b = sqrt($dx * $dx + $dy * $dy);
$x3 = $x4 + $r * $dx / $b;
$y3 = $y4 + $r * $dy / $b;
my @ret = (
[$x1, $y1],
[$x2, $y2],
[$x3, $y3],
[$x4, $y4]
);
return(@ret);
}
sub BezierDat{
my ($t1, @pt) = @_;
my (@x, @y);
for(my $i = 0; $i < @pt; $i++){
$x[$i] = $pt[$i][0];
$y[$i] = $pt[$i][1];
}
my $t2 = $t1 ** 2;
my $t3 = $t1 ** 2;
my $v1 = 1 - $t1;
my $v2 = $v1 ** 2;
my $v3 = $v1 ** 3;
my $x = $v3*$x[0]+3*$v2*$t1*$x[1]+3*$v1*$t2*$x[2]+$t3*$x[3];
my $y = $v3*$y[0]+3*$v2*$t1*$y[1]+3*$v1*$t2*$y[2]+$t3*$y[3];
return([$x, $y]);
}
sub BezierCrv{
my ($seg, @pt) = @_;
my ($x, $y, @xy);
($x, $y) = $pt[0];
unshift(@pt, [$x, $y]);
($x, $y) = $pt[$#pt];
push(@pt, [$x, $y]);
for(my $i = 1; $i <= @pt - 3; $i++){
my @p = (
[$pt[$i - 1][0], $pt[$i - 1][1]],
[$pt[$i + 0][0], $pt[$i + 0][1]],
[$pt[$i + 1][0], $pt[$i + 1][1]],
[$pt[$i + 2][0], $pt[$i + 2][1]]
);
@p = BezierCvt(@p);
push(@xy, [$p[0][0], $p[0][1]]);
for(my $j = 1; $j <= $seg; $j++){
push(@xy, BezierDat($j / $seg, @p));
}
}
return(@xy);
}
;;;sub imgTransCol{
my ($cl) = @_;
return(0)unless($IMG_FLAG0);
return(0)if($cl eq '');
$IMG_IMAG0->Transparent(color=>$cl);
return(1);
}
sub imgDither{
my ($cn, $sw) = @_;
return(0)unless($IMG_FLAG0);
$cn = 5 if($cn eq '');
$sw = 0 if($sw eq '');
$cn = MinMax($cn, 0, 5);
$sw = MinMax($sw, 0, 1);
$sw = ($sw) ? 'true' : 'false';
my @cl = (8, 16, 24, 48, 64, 128, 256);
$IMG_IMAG0->Quantize(colors=>$cl[$cn], dither=>$sw);
return(1);
}
sub imgGray{
return(0)unless($IMG_FLAG0);
$IMG_IMAG0->Quantize(colorspace=>'gray');
return(1);
}
sub imgMono{
my ($sw) = @_;
return(0)unless($IMG_FLAG0);
$sw = ($sw) ? 'true' : 'false';
$IMG_IMAG0->Quantize(colors=>2, dither=>$sw, colorspace=>'gray');
return(1);
}
sub imgContrast{
my ($rd, $sd) = @_;
return(0)unless($IMG_FLAG0);
$rd = '20' if($rd eq '');
$sd = '10' if($sd eq '');
$IMG_IMAG0->Sharpen(radius=>$rd, sigma=>$sd);
return(1);
}
sub imgGamma{
my ($vl) = @_;
return(0)unless($IMG_FLAG0);
return(0)if($vl eq '');
$IMG_IMAG0->Gamma(gamma=>$vl);
return(1);
}
sub imgBright{
my ($vl) = @_;
return(0)unless($IMG_FLAG0);
return(0)if($vl eq '');
$IMG_IMAG0->Modulate(brightness=>$vl);
return(1);
}
sub imgSwitchB{
my ($vl) = @_;
return(0)unless($IMG_FLAG0);
$vl = '30'if($vl eq '');
$IMG_IMAG0->BlackThreshold(threshold=>"$vl%");
return(1);
}
sub imgSwitchW{
my ($vl) = @_;
return(0)unless($IMG_FLAG0);
$vl = '70'if($vl eq '');
$IMG_IMAG0->WhiteThreshold(threshold=>"$vl%");
return(1);
}
sub imgKido{
my ($vl) = @_;
return(0)unless($IMG_FLAG0);
return(0)if($vl eq '');
$IMG_IMAG0->Modulate(saturation=>$vl);
return(1);
}
sub imgHue{
my ($vl) = @_;
return(0)unless($IMG_FLAG0);
return(0)if($vl eq '');
$IMG_IMAG0->Modulate(hue=>$vl);
return(1);
}
sub imgGradation{
my ($c0, $c1) = @_;
return(0)unless($IMG_FLAG0);
return(0)if($c0 eq '');
return(0)if($c1 eq '');
my $wd = $IMG_IMAG0->Get('width');
my $ht = $IMG_IMAG0->Get('height');
my $img = Image::Magick->new;
$img->Set(size=>$wd.'x'.$ht);
$img->ReadImage("gradient:$c0-$c1");
$IMG_IMAG0->Composite(image=>$img, compose=>'over', x=>0, y=>0);
undef($img);
return(1);
}
sub imgFractal{
my ($c0, $c1) = @_;
return(0)unless($IMG_FLAG0);
my $wd = $IMG_IMAG0->Get('width');
my $ht = $IMG_IMAG0->Get('height');
my $img = Image::Magick->new;
$img->Set(size=>$wd.'x'.$ht);
if($c0 || $c1){
$c0 .= "-$c1"if($c1);
$img->ReadImage("plasma:$c0");
}else{
$img->ReadImage('plasma:fractal');
}
$IMG_IMAG0->Composite(image=>$img, compose=>'over', x=>0, y=>0);
undef($img);
return(1);
}
sub imgPattern{
my ($sw) = @_;
return(0)unless($IMG_FLAG0);
my $wd = $IMG_IMAG0->Get('width');
my $ht = $IMG_IMAG0->Get('height');
my $img = Image::Magick->new;
$img->Set(size=>$wd.'x'.$ht);
my $cmp = 'over';
my $til = 'true';
$sw = MinMax($sw, 0, 18);
if($sw == 0){
$img->ReadImage('plasma:fractal');
$IMG_IMAG0->Composite(image=>$img, compose=>'over', x=>0, y=>0);
$img->ReadImage('plasma:fractal');
$cmp = 'plus';
$til = 'false';
}elsif($sw == 1){
$img->ReadImage('ROSE:');
}elsif($sw == 2){
$img->ReadImage('GRANITE:');
}else{
my @pt =(
'BRICKS','CHECKERBOARD','CIRCLES','CROSSHATCH','HS_FDIAGONAL',
'GRAY50','GRAY75','CROSSHATCH30','CROSSHATCH45','FISHSCALES',
'HEXAGONS','OCTAGONS','HS_DIAGCROSS','LEFTSHINGLE',
'VERTICALSAW','VERTICALBRICKS'
);
$img->ReadImage("PATTERN:$pt[$sw - 3]");
$til = 'false';
}
$IMG_IMAG0->Composite(image=>$img, compose=>$cmp, x=>0, y=>0, tile=>$til);
undef($img);
return(1);
}
sub imgVivid{
my ($vl) = @_;
return(0)unless($IMG_FLAG0);
$vl = 50 if($vl eq '');
$IMG_IMAG0->AdaptiveThreshold(
height=>$vl, width=>$vl, offset=>50
);
}
sub imgBlend{
my ($cl, $bl) = @_;
return(0)unless($IMG_FLAG0);
$cl = 'gray' if($cl eq '');
$bl = '50' if($bl eq '');
$bl = MinMax($bl, 0, 100);
$bl = 100 - $bl;
my $img = Image::Magick->new;
my $wd = $IMG_IMAG0->Get('width');
my $ht = $IMG_IMAG0->Get('height');
$img->Set(size=>$wd.'x'.$ht);
$img->ReadImage("xc:$cl");
$IMG_IMAG0->Composite(
image=>$img,
compose=>'Blend',
opacity=>"$bl%",
x=>0, y=>0
);
undef($img);
return(1);
}
sub imgTint{
my ($cl, $op) = @_;
return(0)unless($IMG_FLAG0);
$op = '50' if($op eq '');
$cl = 'blue' if($cl eq '');
$IMG_IMAG0->Tint(fill=>$cl, opacity=>"$op%");
return(1);
}
;;;;sub imgFlip{
return(0)unless($IMG_FLAG0);
$IMG_IMAG0->Flip();
return(1);
}
sub imgFlop{
return(0)unless($IMG_FLAG0);
$IMG_IMAG0->Flop();
return(1);
}
sub imgEqualize{
return(0)unless($IMG_FLAG0);
$IMG_IMAG0->Equalize();
return(1);
}
sub imgImplode{
my ($vl) = @_;
return(0)unless($IMG_FLAG0);
$vl = '0.7'if($vl eq '');
$IMG_IMAG0->Implode(amount=>$vl);
return(1);
}
sub imgTwist{
my ($vl) = @_;
return(0)unless($IMG_FLAG0);
$vl = '40'if($vl eq '');
$IMG_IMAG0->Swirl(degrees=>$vl);
return(1);
}
sub imgShear{
my ($vx, $vy) = @_;
return(0)unless($IMG_FLAG0);
$vx = '15'if($vx eq '');
$vy = '40'if($vy eq '');
$IMG_IMAG0->Shear($vx.'x'.$vy);
return(1);
}
sub imgNega{
return(0)unless($IMG_FLAG0);
$IMG_IMAG0->Negate();
return(1);
}
sub imgFrame{
my ($cl, $wd, $ht, $iw, $ow) = @_;
return(0)unless($IMG_FLAG0);
return(0)unless($wd + $ht);
$wd = '2' if($wd eq '');
$ht = '2' if($ht eq '');
$cl = 'gray' if($cl eq '');
if($iw.$ow eq ''){
$IMG_IMAG0->Border(width=>$wd, height=>$ht, fill=>$cl);
}else{
$iw = '2' if($iw eq '');
$ow = '2' if($ow eq '');
$IMG_IMAG0->Frame(
width=>$wd,
height=>$ht,
outer=>$ow,
inner=>$iw,
fill=>$cl
);
}
return(1);
}
sub imgFrame3D{
my ($sw, $wd, $ht) = @_;
return(0)unless($IMG_FLAG0);
return(0)unless($wd);
return(0)unless($ht);
$wd = '5' if($wd eq '');
$ht = '5' if($ht eq '');
$sw = '1' if($sw eq '');
$sw = ($sw) ? 'true' : 'false';
$IMG_IMAG0->Raise(width=>$wd, height=>$ht, raise=>$sw);
return(1);
}
sub imgMedian{
my ($vl) = @_;
return(0)unless($IMG_FLAG0);
$vl = '20' if($vl eq '');
$IMG_IMAG0->MedianFilter(radius=>$vl);
return(1);
}
sub imgLaplacian{
return(0)unless($IMG_FLAG0);
$IMG_IMAG0->Convolve([1, 1, 1, 1, -6, 1, 1, 1, 1]);
return(1);
}
sub imgGaussian{
return(0)unless($IMG_FLAG0);
$IMG_IMAG0->Convolve([1, 2, 1, 2, 4, 2, 1, 2, 1]);
return(1);
}
sub imgBlur{
my ($sw, $rd, $sd, $ag) = @_;
return(0)unless($IMG_FLAG0);
$sw = MinMax($sw, 0, 3);
if($sw eq '0'){
$rd = '2' if($rd eq '');
$sd = '2' if($sd eq '');
$IMG_IMAG0->Blur(radius=>$rd, sigma=>$sd);
}elsif($sw eq '1'){
$rd = '3' if($rd eq '');
$sd = '2' if($sd eq '');
$IMG_IMAG0->GaussianBlur(radius=>$rd, sigma=>$sd);
}elsif($sw eq '2'){
$rd = '40'if($rd eq '');
$IMG_IMAG0->RadialBlur(angle=>$rd);
}elsif($sw eq '3'){
$rd = '10' if($rd eq '');
$sd = '10' if($sd eq '');
$ag = '45' if($ag eq '');
$IMG_IMAG0->MotionBlur(radius=>$rd, sigma=>$sd, angle=>$ag);
}
return(1);
}
sub imgAddNoise{
my ($vl) = @_;
return(0)unless($IMG_FLAG0);
$vl = '3' if($vl eq '');
my @nz = ('Uniform', 'Gaussian', 'Multiplicative',
'Impulse', 'Laplacian', 'Poisson');
$vl = MinMax($vl, 0, $#nz);
$IMG_IMAG0->AddNoise(noise=>$nz[$vl]);
return(1);
}
sub imgSpread{
my ($vl) = @_;
return(0)unless($IMG_FLAG0);
$vl = '2' if($vl eq '');
$IMG_IMAG0->Spread(radius=>$vl);
return(1);
}
sub imgOilPaint{
my ($vl) = @_;
return(0)unless($IMG_FLAG0);
$vl = '2' if($vl eq '');
$IMG_IMAG0->OilPaint(radius=>$vl);
return(1);
}
sub imgCharcoal{
my ($rd, $sd) = @_;
return(0)unless($IMG_FLAG0);
$rd = '2' if($rd eq '');
$sd = '4' if($sd eq '');
$IMG_IMAG0->Charcoal(radius=>$rd, sigma=>$sd);
return(1);
}
sub imgEdge{
my ($vl) = @_;
return(0)unless($IMG_FLAG0);
$vl = '0.1'if($vl eq '');
$IMG_IMAG0->Edge(radius=>$vl);
return(1);
}
sub imgEmboss{
my ($rd, $sd) = @_;
return(0)unless($IMG_FLAG0);
$rd = '2' if($rd eq '');
$sd = '1' if($sd eq '');
$IMG_IMAG0->Emboss(radius=>$rd, sigma=>$sd);
return(1);
}
sub imgShade{
my ($az, $ev, $sw) = @_;
return(0)unless($IMG_FLAG0);
$az = '99'if($az eq '');
$ev = '50'if($ev eq '');
$sw = '0' if($ev eq '');
$sw = ($sw) ? $sw = 'true' : 'false';
$IMG_IMAG0->Shade(azimuth=>$az, elevation=>$ev, gray=>$sw);
return(1);
}
sub imgSolarize{
my ($vl) = @_;
return(0)unless($IMG_FLAG0);
$vl = '70' if($vl eq '');
$IMG_IMAG0->Solarize(threshold=>$vl);
return(1);
}
sub imgWave{
my ($vw, $vh) = @_;
return(0)unless($IMG_FLAG0);
$vw = '4' if($vw eq '');
$vh = '40' if($vh eq '');
$IMG_IMAG0->Wave($vw.'x'.$vh);
return(1);
}
1;