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