-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathREADME
191 lines (122 loc) · 4.81 KB
/
README
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
RComposite
RComposite is an RMagick abstraction library to easily manipulate and composite
images through the use of a canvas, layers, layer masks, adjustment layers, fill
layers, and layer sets (much like in Photoshop).
Install:
Add the github repository to your gem sources:
sudo gem sources -a http://gems.github.com
Install the gem from github:
sudo gem install corbanbrook-rcomposite
Require:
require 'rubygems'
require 'rcomposite'
include RComposite # optional: if you wish to have the RComposite module in your project scope
...
Class Summary:
* Layers: There are 4 types of Layer Models,
* Layer: The base layer model. Can load an image from disk, blob,
or RMagick Image object. Contains methods to transform, change layer mode,
change opacity level, and more.
* FillLayer: A solid color, gradient, or pattern fill layer.
* AdjustmentLayer: Invert, Threshold, Levels, Blur adjustment layer.
Applies layer effect over everything under it in the layer stack.
* LayerMask: Mask any of the above layer types. LayerMasks are a special
type of layer which is a Alpha Channel mask that can be applied to any
layer type. Since LayerMask is also a layer, it can also be transformed
in any way.
* LayerSets: 2 types of LayerSet Models,
* LayerSet: The LayerSet is a container, or directory in which to bundle
layers. LayerSet contains methods to do group transforms on its bundled
layers. Transforms like rotation, movement and scaling are performed on
all the layers it contains while maintaining each layer on a seperate plane
without merging.
* Canvas: The canvas is a special LayerSet which is a blank workspace containing
other layers and layer sets.
Usage:
* Creating a blank canvas:
canvas = RComposite::Canvas.new(640, 480)
Canvas also accepts an optional block for easily adding layers to the stack
canvas = Rcomposite::Canvas.new(640, 480) do
layer :file => 'butterfly.png'
end
* Creating a layer:
photo = RComposite::Layer.new :file => 'photo.jpg'
* Creating a fill layer:
blue = RCompisite::FillLayer.new '#000090'
* Changing a Layers properties:
blue.opacity 40
blue.mode Multiply
* Adding layers to the canvas. (Whatever is added first will be on top):
canvas.layer blue
canvas.layer photo
* Saving the canvas:
canvas.save_as 'bluesky.jpg'
* Adding an alpha channel mask to a layer:
Masks are used to punch holes into layers to add transparency.
blue.layer_mask :file => 'alpha_channel.png'
You can add layer options to the mask just like it was a normal layer.
fill_layer SolidColor, '#f83898FF' do
layer_mask :file => 'butterfly-mask.png' do
offset -30, -30
rotate 40
end
end
The real power of RComposite lies in its use of blocks and simplified syntax.
Take a look at the following examples:
* Just like the Canvas, all layer types also accept an optional block parametre for setting layer options:
butterfly = RComposite::Layer :file => 'butterfly.png' do
offset 100, 100 # moves the layer on the canvas
rotate 25
end
or..
canvas.layer :file => 'butterfly.png' do
..
end
* DSL Example
Canvas.new(320,240) do
layer_set :slides do
layer :file => 'slide1.png' do
opacity 65
offset 12, 12
mode Lighten
end
adjustment_layer Blur, 0.5, 1.5 do
layer_mask :file => 'butterfly-mask.png'
end
layer :file => 'slide2.png' do
offset 28, 28
opacity 30
mode Darken
end
rotate 45
offset 70, 50
scale 80, 80
end
fill_layer SolidColor, '#f83898FF' do
opacity 70
mode Multiply
layer_mask :file => 'butterfly-mask.png' do
offset -30, -30
image.rotate! 40
end
end
fill_layer Gradient, 0, 0, 0, 50, '#606', '#033' do
opacity 90
mode Overlay
layer_mask :file => 'butterfly-mask.png' do
offset -20, -20
end
end
layer :file => 'background.png' do
image.resize!(320, 240)
end
save_as 'composite.jpg'
end
The nice thing about RComposite is that it doesnt hide the underlaying RMagick
Image object from you. It is always available through the image accessor
layer :file => 'photo.jpg' do
image.crop_resized!(100,300) # crop_resized! is a RMagick method
end
@corban weare.buildingsky.net
________________________________________________________________________________
Copyright (c) 2009 Corban Brook, released under the MIT license