1#!/usr/bin/perl 2# 3# Overall demo of the major PerlMagick methods. 4# 5use Image::Magick; 6 7# 8# Read model & smile image. 9# 10print "Read...\n"; 11$null=Image::Magick->new; 12$null->Set(size=>'70x70'); 13$x=$null->ReadImage('NULL:black'); 14warn "$x" if "$x"; 15 16$model=Image::Magick->new(); 17$x=$model->ReadImage('model.gif'); 18warn "$x" if "$x"; 19$model->Label('Magick'); 20$model->Set(background=>'white'); 21 22$smile=Image::Magick->new; 23$x=$smile->ReadImage('smile.gif'); 24warn "$x" if "$x"; 25$smile->Label('Smile'); 26$smile->Set(background=>'white'); 27# 28# Create image stack. 29# 30print "Transform image...\n"; 31$images=Image::Magick->new(); 32 33print "Adaptive Blur...\n"; 34$example=$model->Clone(); 35$example->Label('Adaptive Blur'); 36$example->AdaptiveBlur('0x1'); 37push(@$images,$example); 38 39print "Adaptive Resize...\n"; 40$example=$model->Clone(); 41$example->Label('Adaptive Resize'); 42$example->AdaptiveResize('60%'); 43push(@$images,$example); 44 45print "Adaptive Sharpen...\n"; 46$example=$model->Clone(); 47$example->Label('Adaptive Sharpen'); 48$example->AdaptiveSharpen('0x1'); 49push(@$images,$example); 50 51print "Adaptive Threshold...\n"; 52$example=$model->Clone(); 53$example->Label('Adaptive Threshold'); 54$example->AdaptiveThreshold('5x5+5%'); 55push(@$images,$example); 56 57print "Add Noise...\n"; 58$example=$model->Clone(); 59$example->Label('Add Noise'); 60$example->AddNoise("Laplacian"); 61push(@$images,$example); 62 63print "Annotate...\n"; 64$example=$model->Clone(); 65$example->Label('Annotate'); 66$example->Annotate(font=>'Generic.ttf',text=>'Magick',geometry=>'+0+20', 67 fill=>'gold',gravity=>'North',pointsize=>14); 68push(@$images,$example); 69 70print "Auto-gamma...\n"; 71$example=$model->Clone(); 72$example->Label('Auto Gamma'); 73$example->AutoGamma(); 74push(@$images,$example); 75 76print "Auto-level...\n"; 77$example=$model->Clone(); 78$example->Label('Auto Level'); 79$example->AutoLevel(); 80push(@$images,$example); 81 82print "Auto-threshold...\n"; 83$example=$model->Clone(); 84$example->Label('Auto Threshold'); 85$example->AutoThreshold(); 86push(@$images,$example); 87 88print "Blilateral Blur...\n"; 89$example=$model->Clone(); 90$example->Label('Blilateral Blur'); 91$example->BilateralBlur('8x8'); 92push(@$images,$example); 93 94print "Blur...\n"; 95$example=$model->Clone(); 96$example->Label('Blur'); 97$example->Blur('0.0x1.0'); 98push(@$images,$example); 99 100print "Border...\n"; 101$example=$model->Clone(); 102$example->Label('Border'); 103$example->Border(geometry=>'6x6',color=>'gold'); 104push(@$images,$example); 105 106print "CLAHE...\n"; 107$example=$model->Clone(); 108$example->Label('CLAHE'); 109$example->CLAHE('128x192+32+3'); 110push(@$images,$example); 111 112print "Channel...\n"; 113$example=$model->Clone(); 114$example->Label('Channel'); 115$example->Channel(channel=>'red'); 116push(@$images,$example); 117 118print "Charcoal...\n"; 119$example=$model->Clone(); 120$example->Label('Charcoal'); 121$example->Charcoal('2x1'); 122push(@$images,$example); 123 124print "ColorMatrix...\n"; 125$example=$model->Clone(); 126$example->Label('ColorMatrix'); 127$example->ColorMatrix([1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0.5, 0, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1]); 128push(@$images,$example); 129 130print "Colorspace...\n"; 131$example=$model->Clone(); 132$example->Label('Colorspace'); 133$example->Colorspace('Lab'); 134push(@$images,$example); 135 136print "Composite...\n"; 137$example=$model->Clone(); 138$example->Label('Composite'); 139$example->Composite(image=>$smile,compose=>'over',geometry=>'+35+65'); 140$example->Clamp(); 141push(@$images,$example); 142 143print "Contrast...\n"; 144$example=$model->Clone(); 145$example->Label('Contrast'); 146$example->Contrast(); 147push(@$images,$example); 148 149print "Contrast Stretch...\n"; 150$example=$model->Clone(); 151$example->Label('Contrast Stretch'); 152$example->ContrastStretch('5%'); 153push(@$images,$example); 154 155print "Convolve...\n"; 156$example=$model->Clone(); 157$example->Label('Convolve'); 158$example->Convolve([0.125, 0.125, 0.125, 0.125, 0.5, 0.125, 0.125, 0.125, 0.125]); 159push(@$images,$example); 160 161print "Crop...\n"; 162$example=$model->Clone(); 163$example->Label('Crop'); 164$example->Crop(geometry=>'80x80+25+50'); 165$example->Set(page=>'0x0+0+0'); 166push(@$images,$example); 167 168print "Despeckle...\n"; 169$example=$model->Clone(); 170$example->Label('Despeckle'); 171$example->Despeckle(); 172push(@$images,$example); 173 174print "Distort...\n"; 175$example=$model->Clone(); 176$example->Label('Distort'); 177$example->Distort(method=>'arc',points=>[60],'virtual-pixel'=>'white'); 178push(@$images,$example); 179 180print "Draw...\n"; 181$example=$model->Clone(); 182$example->Label('Draw'); 183$example->Draw(fill=>'none',stroke=>'gold',primitive=>'circle', 184 points=>'60,90 60,120',strokewidth=>2); 185push(@$images,$example); 186 187print "Detect Edges...\n"; 188$example=$model->Clone(); 189$example->Label('Detect Edges'); 190$example->Edge('2x0.5'); 191$example->Clamp(); 192push(@$images,$example); 193 194print "Emboss...\n"; 195$example=$model->Clone(); 196$example->Label('Emboss'); 197$example->Emboss('0x1'); 198push(@$images,$example); 199 200print "Encipher...\n"; 201$example=$model->Clone(); 202$example->Label('Encipher'); 203$example->Encipher('Magick'); 204push(@$images,$example); 205 206print "Equalize...\n"; 207$example=$model->Clone(); 208$example->Label('Equalize'); 209$example->Equalize(); 210push(@$images,$example); 211 212print "Explode...\n"; 213$example=$model->Clone(); 214$example->Label('Explode'); 215$example->Implode(-1); 216push(@$images,$example); 217 218print "Flip...\n"; 219$example=$model->Clone(); 220$example->Label('Flip'); 221$example->Flip(); 222push(@$images,$example); 223 224print "Flop...\n"; 225$example=$model->Clone(); 226$example->Label('Flop'); 227$example->Flop(); 228push(@$images,$example); 229 230print "Frame...\n"; 231$example=$model->Clone(); 232$example->Label('Frame'); 233$example->Frame('15x15+3+3'); 234push(@$images,$example); 235 236print "Fx...\n"; 237$example=$model->Clone(); 238$example->Label('Fx'); 239push(@$images,$example->Fx(expression=>'0.5*u')); 240 241print "Gamma...\n"; 242$example=$model->Clone(); 243$example->Label('Gamma'); 244$example->Gamma(1.6); 245push(@$images,$example); 246 247print "Gaussian Blur...\n"; 248$example=$model->Clone(); 249$example->Label('Gaussian Blur'); 250$example->GaussianBlur('0.0x1.5'); 251push(@$images,$example); 252 253print "Gradient...\n"; 254$gradient=Image::Magick->new; 255$gradient->Set(size=>'130x194'); 256$x=$gradient->ReadImage('gradient:#20a0ff-#ffff00'); 257warn "$x" if "$x"; 258$gradient->Label('Gradient'); 259push(@$images,$gradient); 260 261print "Grayscale...\n"; 262$example=$model->Clone(); 263$example->Label('Grayscale'); 264$example->Set(type=>'grayscale'); 265push(@$images,$example); 266 267print "Implode...\n"; 268$example=$model->Clone(); 269$example->Label('Implode'); 270$example->Implode(0.5); 271push(@$images,$example); 272 273print "Kuwahara...\n"; 274$example=$model->Clone(); 275$example->Label('Kuwahara'); 276$example->Kuwahara('0x1'); 277push(@$images,$example); 278 279print "Level...\n"; 280$example=$model->Clone(); 281$example->Label('Level'); 282$example->Level('20%x'); 283$example->Clamp(); 284push(@$images,$example); 285 286print "Linear stretch...\n"; 287$example=$model->Clone(); 288$example->Label('Linear Stretch'); 289$example->LinearStretch('5x5'); 290push(@$images,$example); 291 292print "Median Filter...\n"; 293$example=$model->Clone(); 294$example->Label('Median Filter'); 295$example->MedianFilter('4x4'); 296push(@$images,$example); 297 298print "Mode...\n"; 299$example=$model->Clone(); 300$example->Label('Mode'); 301$example->Mode('4x4'); 302push(@$images,$example); 303 304print "Modulate...\n"; 305$example=$model->Clone(); 306$example->Label('Modulate'); 307$example->Modulate(brightness=>110,saturation=>110,hue=>110); 308push(@$images,$example); 309$example=$model->Clone(); 310 311print "Monochrome...\n"; 312$example=$model->Clone(); 313$example->Label('Monochrome'); 314$example->Quantize(colorspace=>'gray',colors=>2,dither=>'false'); 315push(@$images,$example); 316 317print "Morphology...\n"; 318$example=$model->Clone(); 319$example->Label('Morphology'); 320$example->Morphology(method=>'Dilate',kernel=>'Diamond',iterations=>2); 321push(@$images,$example); 322 323print "Motion Blur...\n"; 324$example=$model->Clone(); 325$example->Label('Motion Blur'); 326$example->MotionBlur('0x13+10-10'); 327push(@$images,$example); 328 329print "Negate...\n"; 330$example=$model->Clone(); 331$example->Label('Negate'); 332$example->Negate(); 333push(@$images,$example); 334 335print "Normalize...\n"; 336$example=$model->Clone(); 337$example->Label('Normalize'); 338$example->Normalize(); 339push(@$images,$example); 340 341print "Oil Paint...\n"; 342$example=$model->Clone(); 343$example->Label('Oil Paint'); 344$example->OilPaint('2x0.5'); 345push(@$images,$example); 346 347print "Plasma...\n"; 348$plasma=Image::Magick->new; 349$plasma->Set(size=>'130x194'); 350$x=$plasma->ReadImage('plasma:fractal'); 351warn "$x" if "$x"; 352$plasma->Label('Plasma'); 353push(@$images,$plasma); 354 355print "Polaroid...\n"; 356$example=$model->Clone(); 357$example->Label('Polaroid'); 358$example->Polaroid(caption=>'Magick',angle=>-5.0,gravity=>'center'); 359push(@$images,$example); 360 361print "Posterize...\n"; 362$example=$model->Clone(); 363$example->Label('Posterize'); 364$example->Posterize(5); 365push(@$images,$example); 366 367print "Quantize...\n"; 368$example=$model->Clone(); 369$example->Label('Quantize'); 370$example->Quantize(); 371push(@$images,$example); 372 373print "Rotational Blur...\n"; 374$example=$model->Clone(); 375$example->Label('Rotational Blur'); 376$example->RotationalBlur(10); 377push(@$images,$example); 378 379print "Raise...\n"; 380$example=$model->Clone(); 381$example->Label('Raise'); 382$example->Raise('10x10'); 383push(@$images,$example); 384 385print "Reduce Noise...\n"; 386$example=$model->Clone(); 387$example->Label('Reduce Noise'); 388$example->ReduceNoise('2x2'); 389push(@$images,$example); 390 391print "Resize...\n"; 392$example=$model->Clone(); 393$example->Label('Resize'); 394$example->Resize('60%'); 395push(@$images,$example); 396 397print "Roll...\n"; 398$example=$model->Clone(); 399$example->Label('Roll'); 400$example->Roll(geometry=>'+20+10'); 401push(@$images,$example); 402 403print "Rotate...\n"; 404$example=$model->Clone(); 405$example->Label('Rotate'); 406$example->Rotate(45); 407push(@$images,$example); 408 409print "Sample...\n"; 410$example=$model->Clone(); 411$example->Label('Sample'); 412$example->Sample('60%'); 413push(@$images,$example); 414 415print "Scale...\n"; 416$example=$model->Clone(); 417$example->Label('Scale'); 418$example->Scale('60%'); 419push(@$images,$example); 420 421print "Segment...\n"; 422$example=$model->Clone(); 423$example->Label('Segment'); 424$example->Segment(); 425push(@$images,$example); 426 427print "Shade...\n"; 428$example=$model->Clone(); 429$example->Label('Shade'); 430$example->Shade(geometry=>'30x30',gray=>'true'); 431push(@$images,$example); 432 433print "Sharpen...\n"; 434$example=$model->Clone(); 435$example->Label('Sharpen'); 436$example->Sharpen('0.0x1.0'); 437$example->Clamp(); 438push(@$images,$example); 439 440print "Shave...\n"; 441$example=$model->Clone(); 442$example->Label('Shave'); 443$example->Shave('10x10'); 444push(@$images,$example); 445 446print "Shear...\n"; 447$example=$model->Clone(); 448$example->Label('Shear'); 449$example->Shear('-20x20'); 450push(@$images,$example); 451 452print "Sketch...\n"; 453$example=$model->Clone(); 454$example->Label('Sketch'); 455$example->Set(colorspace=>'Gray'); 456$example->Sketch('0x20+120'); 457push(@$images,$example); 458 459print "Sigmoidal Contrast...\n"; 460$example=$model->Clone(); 461$example->Label('Sigmoidal Contrast'); 462$example->SigmoidalContrast("3x50%"); 463push(@$images,$example); 464 465print "Spread...\n"; 466$example=$model->Clone(); 467$example->Label('Spread'); 468$example->Spread(); 469push(@$images,$example); 470 471print "Solarize...\n"; 472$example=$model->Clone(); 473$example->Label('Solarize'); 474$example->Solarize(); 475push(@$images,$example); 476 477print "Swirl...\n"; 478$example=$model->Clone(); 479$example->Label('Swirl'); 480$example->Swirl(90); 481push(@$images,$example); 482 483print "Tint...\n"; 484$example=$model->Clone(); 485$example->Label('Tint'); 486$example->Tint('wheat'); 487push(@$images,$example); 488 489print "Unsharp Mask...\n"; 490$example=$model->Clone(); 491$example->Label('Unsharp Mask'); 492$example->UnsharpMask('0.0x1.0'); 493$example->Clamp(); 494push(@$images,$example); 495 496print "Vignette...\n"; 497$example=$model->Clone(); 498$example->Label('Vignette'); 499$example->Vignette('0x20'); 500push(@$images,$example); 501 502print "Wave...\n"; 503$example=$model->Clone(); 504$example->Label('Wave'); 505$example->Wave('25x150'); 506push(@$images,$example); 507 508print "WaveletDenoise...\n"; 509$example=$model->Clone(); 510$example->Label('Wavelet Denoise'); 511$example->WaveletDenoise('5%'); 512push(@$images,$example); 513 514# 515# Create image montage. 516# 517print "Montage...\n"; 518$montage=$images->Montage(font=>'Generic.ttf',geometry=>'140x160+8+4>', 519 gravity=>'Center',tile=>'5x+10+200',compose=>'over',background=>'#ffffff', 520 pointsize=>18,fill=>'#600',stroke=>'none',shadow=>'true'); 521 522$logo=Image::Magick->new(); 523$logo->Read('logo:'); 524$logo->Zoom('40%'); 525$montage->Composite(image=>$logo,gravity=>'North'); 526 527print "Write...\n"; 528$montage->Set(matte=>'false'); 529$montage->Write('demo.jpg'); 530print "Display...\n"; 531$montage->Write('win:'); 532