corbanbrook-rcomposite 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +111 -55
- data/lib/rcomposite/layer.rb +4 -0
- data/lib/rcomposite/layerset.rb +21 -19
- data/lib/rcomposite.rb +1 -0
- metadata +4 -3
data/README
CHANGED
@@ -1,6 +1,30 @@
|
|
1
1
|
|
2
2
|
RComposite
|
3
3
|
|
4
|
+
RComposite is an RMagick abstraction library to easily manipulate and composite
|
5
|
+
images through the use of a canvas, layers, layer masks, adjustment layers, fill
|
6
|
+
layers, and layer sets (much like in Photoshop).
|
7
|
+
|
8
|
+
|
9
|
+
Install:
|
10
|
+
|
11
|
+
Add the github repository to your gem sources:
|
12
|
+
|
13
|
+
sudo gem sources -a http://gems.github.com
|
14
|
+
|
15
|
+
Install the gem from github:
|
16
|
+
|
17
|
+
sudo gem install corbanbrook-rcomposite
|
18
|
+
|
19
|
+
Require:
|
20
|
+
|
21
|
+
require 'rubygems'
|
22
|
+
require 'rcomposite'
|
23
|
+
|
24
|
+
include RComposite # optional: if you wish to have the RComposite module in your project scope
|
25
|
+
|
26
|
+
...
|
27
|
+
|
4
28
|
|
5
29
|
Class Summary:
|
6
30
|
|
@@ -34,92 +58,124 @@ Class Summary:
|
|
34
58
|
|
35
59
|
Usage:
|
36
60
|
|
37
|
-
|
61
|
+
* Creating a blank canvas:
|
38
62
|
|
39
|
-
|
40
|
-
require 'rcomposite'
|
41
|
-
include RComposite # includes the RComposite module methods into this scope
|
63
|
+
canvas = RComposite::Canvas.new(640, 480)
|
42
64
|
|
43
|
-
|
65
|
+
Canvas also accepts an optional block for easily adding layers to the stack
|
44
66
|
|
45
|
-
|
67
|
+
canvas = Rcomposite::Canvas.new(640, 480) do
|
68
|
+
layer :file => 'butterfly.png'
|
69
|
+
end
|
46
70
|
|
47
|
-
Creating a layer:
|
71
|
+
* Creating a layer:
|
48
72
|
|
49
|
-
|
73
|
+
photo = RComposite::Layer.new :file => 'photo.jpg'
|
50
74
|
|
51
|
-
Creating a fill layer:
|
75
|
+
* Creating a fill layer:
|
52
76
|
|
53
|
-
|
77
|
+
blue = RCompisite::FillLayer.new '#000090'
|
54
78
|
|
55
|
-
Changing a Layers properties:
|
79
|
+
* Changing a Layers properties:
|
56
80
|
|
57
|
-
|
58
|
-
|
81
|
+
blue.opacity 40
|
82
|
+
blue.mode Multiply
|
59
83
|
|
60
|
-
|
84
|
+
* Adding layers to the canvas. (Whatever is added first will be on top):
|
61
85
|
|
62
|
-
|
63
|
-
|
86
|
+
canvas.layer blue
|
87
|
+
canvas.layer photo
|
64
88
|
|
65
|
-
|
89
|
+
* Saving the canvas:
|
66
90
|
|
67
|
-
|
91
|
+
canvas.save_as 'bluesky.jpg'
|
68
92
|
|
69
|
-
|
70
|
-
Take a look at the following example:
|
93
|
+
* Adding an alpha channel mask to a layer:
|
71
94
|
|
72
|
-
|
95
|
+
Masks are used to punch holes into layers to add transparency.
|
73
96
|
|
74
|
-
|
75
|
-
layer :file => 'slide1.png' do
|
76
|
-
opacity 65
|
77
|
-
offset 12, 12
|
78
|
-
mode Lighten
|
79
|
-
end
|
97
|
+
blue.layer_mask :file => 'alpha_channel.png'
|
80
98
|
|
81
|
-
|
82
|
-
layer_mask :file => 'butterfly-mask.png'
|
83
|
-
end
|
99
|
+
You can add layer options to the mask just like it was a normal layer.
|
84
100
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
101
|
+
fill_layer SolidColor, '#f83898FF' do
|
102
|
+
layer_mask :file => 'butterfly-mask.png' do
|
103
|
+
offset -30, -30
|
104
|
+
rotate 40
|
89
105
|
end
|
106
|
+
end
|
90
107
|
|
91
|
-
|
92
|
-
|
93
|
-
|
108
|
+
|
109
|
+
The real power of RComposite lies in its use of blocks and simplified syntax.
|
110
|
+
Take a look at the following examples:
|
111
|
+
|
112
|
+
* Just like the Canvas, all layer types also accept an optional block parametre for setting layer options:
|
113
|
+
|
114
|
+
butterfly = RComposite::Layer :file => 'butterfly.png' do
|
115
|
+
offset 100, 100 # moves the layer on the canvas
|
116
|
+
rotate 25
|
94
117
|
end
|
95
118
|
|
96
|
-
|
97
|
-
opacity 70
|
98
|
-
mode Multiply
|
119
|
+
or..
|
99
120
|
|
100
|
-
|
101
|
-
|
102
|
-
image.rotate! 40
|
103
|
-
end
|
121
|
+
canvas.layer :file => 'butterfly.png' do
|
122
|
+
..
|
104
123
|
end
|
105
124
|
|
106
|
-
|
107
|
-
opacity 90
|
108
|
-
mode Overlay
|
125
|
+
* DSL Example
|
109
126
|
|
110
|
-
|
111
|
-
|
127
|
+
Canvas.new(320,240) do
|
128
|
+
|
129
|
+
layer_set :slides do
|
130
|
+
layer :file => 'slide1.png' do
|
131
|
+
opacity 65
|
132
|
+
offset 12, 12
|
133
|
+
mode Lighten
|
134
|
+
end
|
135
|
+
|
136
|
+
adjustment_layer Blur, 0.5, 1.5 do
|
137
|
+
layer_mask :file => 'butterfly-mask.png'
|
138
|
+
end
|
139
|
+
|
140
|
+
layer :file => 'slide2.png' do
|
141
|
+
offset 28, 28
|
142
|
+
opacity 30
|
143
|
+
mode Darken
|
144
|
+
end
|
145
|
+
|
146
|
+
rotate 45
|
147
|
+
offset 70, 50
|
148
|
+
scale 80, 80
|
112
149
|
end
|
113
|
-
end
|
114
150
|
|
115
|
-
|
116
|
-
|
151
|
+
fill_layer SolidColor, '#f83898FF' do
|
152
|
+
opacity 70
|
153
|
+
mode Multiply
|
154
|
+
|
155
|
+
layer_mask :file => 'butterfly-mask.png' do
|
156
|
+
offset -30, -30
|
157
|
+
image.rotate! 40
|
158
|
+
end
|
159
|
+
end
|
160
|
+
|
161
|
+
fill_layer Gradient, 0, 0, 0, 50, '#606', '#033' do
|
162
|
+
opacity 90
|
163
|
+
mode Overlay
|
164
|
+
|
165
|
+
layer_mask :file => 'butterfly-mask.png' do
|
166
|
+
offset -20, -20
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
layer :file => 'background.png' do
|
171
|
+
image.resize!(320, 240)
|
172
|
+
end
|
173
|
+
|
174
|
+
save_as 'composite.jpg'
|
117
175
|
end
|
118
176
|
|
119
|
-
save_as 'composite.jpg'
|
120
|
-
end
|
121
177
|
|
122
|
-
|
178
|
+
The nice thing about RComposite is that it doesnt hide the underlaying RMagick
|
123
179
|
Image object from you. It is always available through the image accessor
|
124
180
|
|
125
181
|
layer :file => 'photo.jpg' do
|
data/lib/rcomposite/layer.rb
CHANGED
data/lib/rcomposite/layerset.rb
CHANGED
@@ -5,7 +5,6 @@ module RComposite
|
|
5
5
|
|
6
6
|
def initialize(name, &block)
|
7
7
|
@layers = []
|
8
|
-
@layer_sets = {}
|
9
8
|
|
10
9
|
bounding_box
|
11
10
|
@name = name
|
@@ -13,23 +12,25 @@ module RComposite
|
|
13
12
|
self.instance_eval &block if block_given?
|
14
13
|
end
|
15
14
|
|
16
|
-
def
|
17
|
-
if
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
# referencing a previously added LayerSet.
|
25
|
-
set = @layer_sets[set_or_name]
|
26
|
-
|
15
|
+
def stack(&block)
|
16
|
+
self.instance_eval &block if block_given?
|
17
|
+
end
|
18
|
+
|
19
|
+
def layer_set(ref, position = :bottom, &block)
|
20
|
+
if ref.is_a? RComposite::LayerSet
|
21
|
+
# referencing a previously instanstiated LayerSet.
|
22
|
+
set = ref
|
27
23
|
else
|
28
|
-
# creating a new LayerSet
|
29
|
-
set = LayerSet.new
|
30
|
-
@layers << set
|
31
|
-
@layer_sets[set_or_name] = set
|
24
|
+
# creating a new LayerSet
|
25
|
+
set = LayerSet.new ref
|
32
26
|
end
|
27
|
+
|
28
|
+
# Add layer set to render pipeline
|
29
|
+
if position == :bottom
|
30
|
+
@layers << set
|
31
|
+
elsif position == :top
|
32
|
+
@layers.unshift set
|
33
|
+
end
|
33
34
|
|
34
35
|
# tie floating block methods (layer, rotate, offset, etc) to LayerSet object.
|
35
36
|
set.instance_eval &block if block_given?
|
@@ -43,6 +44,8 @@ module RComposite
|
|
43
44
|
else
|
44
45
|
layer = Layer.new options
|
45
46
|
end
|
47
|
+
|
48
|
+
# Add layer to render pipeline
|
46
49
|
@layers << layer
|
47
50
|
|
48
51
|
# tie floating block methods (opacity, mode, offset, etc) to Layer object.
|
@@ -76,7 +79,6 @@ module RComposite
|
|
76
79
|
|
77
80
|
# clear layers and sets
|
78
81
|
@layers.clear
|
79
|
-
@layer_sets.clear
|
80
82
|
|
81
83
|
# only 1 flattened layer now
|
82
84
|
@layers << Layer.new(flattened_image)
|
@@ -114,7 +116,7 @@ module RComposite
|
|
114
116
|
@layers.delete(layer)
|
115
117
|
bounding_box
|
116
118
|
end
|
117
|
-
|
119
|
+
|
118
120
|
def bounding_box
|
119
121
|
if @layers.size > 0
|
120
122
|
x1 = []
|
@@ -181,7 +183,7 @@ module RComposite
|
|
181
183
|
new_mid_x = ((layer_mid_x * cos) - (layer_mid_y * sin)).round
|
182
184
|
new_mid_y = ((layer_mid_x * sin) + (layer_mid_y * cos)).round
|
183
185
|
|
184
|
-
layer.
|
186
|
+
layer.rotate(degrees)
|
185
187
|
|
186
188
|
new_offset_x = new_mid_x - (layer.width/2.0).round + @min_x + bounding_mid_x
|
187
189
|
new_offset_y = new_mid_y * -1 - (layer.height/2.0).round + @min_y + bounding_mid_y
|
data/lib/rcomposite.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: corbanbrook-rcomposite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Corban Brook
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-
|
12
|
+
date: 2009-08-13 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -43,6 +43,7 @@ files:
|
|
43
43
|
- lib/rcomposite/layermask.rb
|
44
44
|
has_rdoc: true
|
45
45
|
homepage: http://github.com/corbanbrook/rcomposite
|
46
|
+
licenses:
|
46
47
|
post_install_message:
|
47
48
|
rdoc_options: []
|
48
49
|
|
@@ -63,7 +64,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
63
64
|
requirements: []
|
64
65
|
|
65
66
|
rubyforge_project:
|
66
|
-
rubygems_version: 1.
|
67
|
+
rubygems_version: 1.3.5
|
67
68
|
signing_key:
|
68
69
|
specification_version: 2
|
69
70
|
summary: An RMagick abstration layer for easy image compositing
|