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