3 # Demonstration of some of the fancier Image Composition Methods
4 # including the 'rotate' parameter specific to PerlMagick Composite()
6 # NOTE: versions of IM older than IM v6.5.3-4 will need to rename the
7 # parameter "args=>" to the mis-named "blend=>" parameter.
9 # Also not that "composite -watermark" is actually known as the compose
12 # Essentually each image is equivelent to
13 # convert logo: -crop 80x80+140+60 +repage \
14 # -size 60x60 gradient:black-white \
15 # -alpha set miff:- |\
16 # composite - -geometry +10+10 -virtual-pixel gray \
17 # -dissolve 70x30 show:
18 # for various composition methods.
23 # Background or Destination image
24 my $dest=Image::Magick->new();
26 $dest->Crop('100x100+400+100'); # wizards hat
27 $dest->Set(page=>'0x0+0+0');
28 $dest->Set(alpha=>'Set');
30 # Source, Composite or Overlay image
31 my $src=Image::Magick->new();
32 $src->Set(size=>'80x80');
33 $src->Read('gradient:black-white');
34 $src->Set(alpha=>'Set');
38 # Circle Mask Image (same size as Destination)
39 my $circle=Image::Magick->new();
40 $circle->Set(size=>'100x100');
41 $circle->Read('xc:black');
42 $circle->Draw(fill=>'white',primitive=>'circle',points=>'49.5,49.5 10,49.5');
44 my $texture=Image::Magick->new();
45 $texture->Read('pattern:checkerboard');
47 # List of images generated
48 my $results=Image::Magick->new();
50 # Working copy of Destination Image
53 # ----------------------------------------
54 # Normal Composition Methods
56 $clone=$dest->Clone();
57 $clone->Label('Over\n(normal compose)');
63 push(@$results, $clone);
65 $clone=$dest->Clone();
66 $clone->Label('Multiply\n(add black)');
72 push(@$results, $clone);
74 $clone=$dest->Clone();
75 $clone->Label('Screen\n(add white)');
81 push(@$results, $clone);
83 $clone=$dest->Clone();
84 $clone->Label('HardLight\n(light effects)');
90 push(@$results, $clone);
93 # Masked and Blending Demonstartion
95 $clone=$dest->Clone();
96 $clone->Label('Circle Masked\n(three image)');
103 push(@$results, $clone);
105 $clone=$dest->Clone();
106 $clone->Label('Blend 50x50\n(50% plus 50%)');
113 push(@$results, $clone);
115 $clone=$dest->Clone();
116 $clone->Label('Dissolve 50x50\n(50% over 50%)');
123 push(@$results, $clone);
125 $clone=$dest->Clone();
126 $clone->Label('Dissolve 50\n(50% over 100%)');
133 push(@$results, $clone);
136 # Displacement Demonstartion
138 $clone=$dest->Clone();
139 $clone->Label('Displace 50x0\n(displace horiz)');
140 $clone->Set('virtual-pixel'=>'gray');
147 push(@$results, $clone);
149 $clone=$dest->Clone();
150 $clone->Label('Displace 0x50\n(compress vert)');
151 $clone->Set('virtual-pixel'=>'gray');
158 push(@$results, $clone);
160 $clone=$dest->Clone();
161 $clone->Label('Displace 50x50\n(diagonal)');
162 $clone->Set('virtual-pixel'=>'gray');
169 push(@$results, $clone);
171 $clone=$dest->Clone();
172 $clone->Label('Displace 0,-80\n(displace flip)');
173 $clone->Set('virtual-pixel'=>'gray');
180 push(@$results, $clone);
183 # Demonstrate rotation
184 # note that offset is automatically adjusted to keep rotated image
185 # centered relative to its '0' rotation position
187 $clone=$dest->Clone();
188 $clone->Label('Rotate 0\n');
196 push(@$results, $clone);
198 $clone=$dest->Clone();
199 $clone->Label('Rotate 10\n');
207 push(@$results, $clone);
209 $clone=$dest->Clone();
210 $clone->Label('Rotate 45\n');
218 push(@$results, $clone);
220 $clone=$dest->Clone();
221 $clone->Label('Rotate 90\n');
229 push(@$results, $clone);
231 # ----------------------------------------
232 # Output the changed pixels
234 # to every image underlay a checkboard pattern
235 # so as to show if any transparency is present
236 for my $image ( @$results ) {
244 my $montage=$results->Montage(
250 $montage->Write('show:');
251 $montage->Write('compose_specials.jpg');