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