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