-
Notifications
You must be signed in to change notification settings - Fork 2
/
composite.rb.html
157 lines (124 loc) · 5.93 KB
/
composite.rb.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
<!DOCTYPE public PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta name="generator" content="ex2html.rb" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="css/popup.css" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/styles/github.min.css" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.9.0/highlight.min.js"></script>
<script>
hljs.configure({ cssSelector: "pre" });
hljs.highlightAll();
</script>
<title>RMagick example: composite.rb</title>
</head>
<body>
<h1>composite.rb</h1>
<div class="bodybox">
<div class="bodyfloat">
<pre class="language-ruby">
# frozen_string_literal: true
# Demonstrate the effects of various composite operators.
# Based on ImageMagick's composite test.
require 'rmagick'
ROWS = 70
COLS = 70
COLOR_A = '#999966'
COLOR_B = '#990066'
img = Magick::Image.new(COLS, ROWS)
triangle = Magick::Draw.new
triangle.fill(COLOR_A)
triangle.stroke('transparent')
triangle.polygon(0, 0, COLS, 0, 0, ROWS, 0, 0)
triangle.draw(img)
image_a = img.transparent('white', alpha: Magick::TransparentAlpha)
image_a['Label'] = 'A'
img = Magick::Image.new(COLS, ROWS)
triangle = Magick::Draw.new
triangle.fill(COLOR_B)
triangle.stroke('transparent')
triangle.polygon(0, 0, COLS, ROWS, COLS, 0, 0, 0)
triangle.draw(img)
image__b = img.transparent('white', alpha: Magick::TransparentAlpha)
image__b['Label'] = 'B'
list = Magick::ImageList.new
null = Magick::Image.read('xc:white') { |options| options.size = Magick::Geometry.new(COLS, ROWS) }
null = null.first.transparent('white', alpha: Magick::TransparentAlpha)
null.border_color = 'transparent'
granite = Magick::Image.read('granite:')
list << null.copy
list << image_a
list << image__b
list << null.copy
list << image__b.composite(image_a, Magick::CenterGravity, Magick::OverCompositeOp)
list.cur_image['Label'] = 'A over B'
list << image_a.composite(image__b, Magick::CenterGravity, Magick::OverCompositeOp)
list.cur_image['Label'] = 'B over A'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::InCompositeOp)
list.cur_image['Label'] = 'A in B'
list << image_a.composite(image__b, Magick::CenterGravity, Magick::InCompositeOp)
list.cur_image['Label'] = 'B in A'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::OutCompositeOp)
list.cur_image['Label'] = 'A out B'
list << image_a.composite(image__b, Magick::CenterGravity, Magick::OutCompositeOp)
list.cur_image['Label'] = 'B out A'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::AtopCompositeOp)
list.cur_image['Label'] = 'A atop B'
list << image_a.composite(image__b, Magick::CenterGravity, Magick::AtopCompositeOp)
list.cur_image['Label'] = 'B atop A'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::XorCompositeOp)
list.cur_image['Label'] = 'A xor B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::MultiplyCompositeOp)
list.cur_image['Label'] = 'A multiply B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::ScreenCompositeOp)
list.cur_image['Label'] = 'A screen B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::DarkenCompositeOp)
list.cur_image['Label'] = 'A darken B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::LightenCompositeOp)
list.cur_image['Label'] = 'A lighten B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::PlusCompositeOp)
list.cur_image['Label'] = 'A plus B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::MinusDstCompositeOp)
list.cur_image['Label'] = 'A minus B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::ModulusAddCompositeOp)
list.cur_image['Label'] = 'A add B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::ModulusSubtractCompositeOp)
list.cur_image['Label'] = 'A subtract B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::DifferenceCompositeOp)
list.cur_image['Label'] = 'A difference B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::HueCompositeOp)
list.cur_image['Label'] = 'A hue B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::SaturateCompositeOp)
list.cur_image['Label'] = 'A saturate B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::LuminizeCompositeOp)
list.cur_image['Label'] = 'A luminize B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::ColorizeCompositeOp)
list.cur_image['Label'] = 'A colorize B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::BumpmapCompositeOp)
list.cur_image['Label'] = 'A bumpmap B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::DissolveCompositeOp)
list.cur_image['Label'] = 'A dissolve B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::ThresholdCompositeOp)
list.cur_image['Label'] = 'A threshold B'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::ModulateCompositeOp)
list.cur_image['Label'] = 'A modulate B'
list << image_a.composite(image__b, Magick::CenterGravity, Magick::ModulateCompositeOp)
list.cur_image['Label'] = 'B modulate A'
list << image__b.composite(image_a, Magick::CenterGravity, Magick::OverlayCompositeOp)
list.cur_image['Label'] = 'A overlay B'
montage = list.montage do |options|
options.geometry = Magick::Geometry.new(COLS, ROWS, 3, 3)
rows = (list.size + 3) / 4
options.tile = Magick::Geometry.new(4, rows)
options.texture = granite[0]
options.fill = 'white'
options.stroke = 'transparent'
end
montage.write('composite.gif')
exit
</pre>
</div>
</div>
<div id="close"><a href="javascript:window.close();">Close window</a></div>
</body>
</html>