rubyshop 0.0.2 → 0.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/MIT-LICENSE +20 -0
- data/README +191 -0
- data/lib/rcomposite.rb +9 -0
- data/lib/{rubyshop → rcomposite}/adjustmentlayer.rb +1 -1
- data/lib/{rubyshop → rcomposite}/canvas.rb +3 -3
- data/lib/{rubyshop → rcomposite}/filllayer.rb +2 -2
- data/lib/{rubyshop → rcomposite}/layer.rb +5 -1
- data/lib/{rubyshop → rcomposite}/layermask.rb +1 -1
- data/lib/{rubyshop → rcomposite}/layerset.rb +25 -23
- metadata +59 -48
- data/LICENSE +0 -20
- data/lib/rubyshop.rb +0 -8
- data/lib/rubyshop/rubyshop.rb +0 -7
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Corban Brook
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,191 @@
|
|
1
|
+
|
2
|
+
RComposite
|
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
|
+
|
28
|
+
|
29
|
+
Class Summary:
|
30
|
+
|
31
|
+
* Layers: There are 4 types of Layer Models,
|
32
|
+
|
33
|
+
* Layer: The base layer model. Can load an image from disk, blob,
|
34
|
+
or RMagick Image object. Contains methods to transform, change layer mode,
|
35
|
+
change opacity level, and more.
|
36
|
+
|
37
|
+
* FillLayer: A solid color, gradient, or pattern fill layer.
|
38
|
+
|
39
|
+
* AdjustmentLayer: Invert, Threshold, Levels, Blur adjustment layer.
|
40
|
+
Applies layer effect over everything under it in the layer stack.
|
41
|
+
|
42
|
+
* LayerMask: Mask any of the above layer types. LayerMasks are a special
|
43
|
+
type of layer which is a Alpha Channel mask that can be applied to any
|
44
|
+
layer type. Since LayerMask is also a layer, it can also be transformed
|
45
|
+
in any way.
|
46
|
+
|
47
|
+
* LayerSets: 2 types of LayerSet Models,
|
48
|
+
|
49
|
+
* LayerSet: The LayerSet is a container, or directory in which to bundle
|
50
|
+
layers. LayerSet contains methods to do group transforms on its bundled
|
51
|
+
layers. Transforms like rotation, movement and scaling are performed on
|
52
|
+
all the layers it contains while maintaining each layer on a seperate plane
|
53
|
+
without merging.
|
54
|
+
|
55
|
+
* Canvas: The canvas is a special LayerSet which is a blank workspace containing
|
56
|
+
other layers and layer sets.
|
57
|
+
|
58
|
+
|
59
|
+
Usage:
|
60
|
+
|
61
|
+
* Creating a blank canvas:
|
62
|
+
|
63
|
+
canvas = RComposite::Canvas.new(640, 480)
|
64
|
+
|
65
|
+
Canvas also accepts an optional block for easily adding layers to the stack
|
66
|
+
|
67
|
+
canvas = Rcomposite::Canvas.new(640, 480) do
|
68
|
+
layer :file => 'butterfly.png'
|
69
|
+
end
|
70
|
+
|
71
|
+
* Creating a layer:
|
72
|
+
|
73
|
+
photo = RComposite::Layer.new :file => 'photo.jpg'
|
74
|
+
|
75
|
+
* Creating a fill layer:
|
76
|
+
|
77
|
+
blue = RCompisite::FillLayer.new '#000090'
|
78
|
+
|
79
|
+
* Changing a Layers properties:
|
80
|
+
|
81
|
+
blue.opacity 40
|
82
|
+
blue.mode Multiply
|
83
|
+
|
84
|
+
* Adding layers to the canvas. (Whatever is added first will be on top):
|
85
|
+
|
86
|
+
canvas.layer blue
|
87
|
+
canvas.layer photo
|
88
|
+
|
89
|
+
* Saving the canvas:
|
90
|
+
|
91
|
+
canvas.save_as 'bluesky.jpg'
|
92
|
+
|
93
|
+
* Adding an alpha channel mask to a layer:
|
94
|
+
|
95
|
+
Masks are used to punch holes into layers to add transparency.
|
96
|
+
|
97
|
+
blue.layer_mask :file => 'alpha_channel.png'
|
98
|
+
|
99
|
+
You can add layer options to the mask just like it was a normal layer.
|
100
|
+
|
101
|
+
fill_layer SolidColor, '#f83898FF' do
|
102
|
+
layer_mask :file => 'butterfly-mask.png' do
|
103
|
+
offset -30, -30
|
104
|
+
rotate 40
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
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
|
117
|
+
end
|
118
|
+
|
119
|
+
or..
|
120
|
+
|
121
|
+
canvas.layer :file => 'butterfly.png' do
|
122
|
+
..
|
123
|
+
end
|
124
|
+
|
125
|
+
* DSL Example
|
126
|
+
|
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
|
149
|
+
end
|
150
|
+
|
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'
|
175
|
+
end
|
176
|
+
|
177
|
+
|
178
|
+
The nice thing about RComposite is that it doesnt hide the underlaying RMagick
|
179
|
+
Image object from you. It is always available through the image accessor
|
180
|
+
|
181
|
+
layer :file => 'photo.jpg' do
|
182
|
+
image.crop_resized!(100,300) # crop_resized! is a RMagick method
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
@corban weare.buildingsky.net
|
188
|
+
________________________________________________________________________________
|
189
|
+
|
190
|
+
Copyright (c) 2009 Corban Brook, released under the MIT license
|
191
|
+
|
data/lib/rcomposite.rb
ADDED
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module RComposite
|
2
2
|
class Canvas < LayerSet
|
3
3
|
attr_reader :width, :height
|
4
4
|
attr_accessor :image
|
@@ -7,8 +7,8 @@ module Rubyshop
|
|
7
7
|
@image = Magick::Image.new width, height
|
8
8
|
@width = width
|
9
9
|
@height = height
|
10
|
-
$
|
11
|
-
$
|
10
|
+
$RCompositeCanvasWidth = @width
|
11
|
+
$RCompositeCanvasHeight = @height
|
12
12
|
|
13
13
|
super(:canvas, &block)
|
14
14
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module RComposite
|
2
2
|
# Fill layer types
|
3
3
|
|
4
4
|
SolidColor = 0
|
@@ -32,7 +32,7 @@ module Rubyshop
|
|
32
32
|
fill = Magick::TextureFill.new(image)
|
33
33
|
end
|
34
34
|
|
35
|
-
@image = Magick::Image.new($
|
35
|
+
@image = Magick::Image.new($RCompositeCanvasWidth, $RCompositeCanvasHeight, fill)
|
36
36
|
|
37
37
|
@image.matte = true
|
38
38
|
@mode = Normal
|
@@ -1,4 +1,4 @@
|
|
1
|
-
module
|
1
|
+
module RComposite
|
2
2
|
# Layer mode constants
|
3
3
|
# some of photoshops layer modes are directly equvilent to RMagick
|
4
4
|
# some are not, and some arent supported at all.
|
@@ -80,6 +80,10 @@ module Rubyshop
|
|
80
80
|
@offset_y = y
|
81
81
|
end
|
82
82
|
|
83
|
+
def rotate(degrees)
|
84
|
+
@image.rotate!(degrees)
|
85
|
+
end
|
86
|
+
|
83
87
|
def opacity(percent)
|
84
88
|
@opacity_percent = percent
|
85
89
|
# intercept original alpha channel with pixel intensity
|
@@ -1,11 +1,10 @@
|
|
1
|
-
module
|
1
|
+
module RComposite
|
2
2
|
class LayerSet
|
3
3
|
attr_accessor :layers
|
4
4
|
attr_reader :min_x, :min_y, :max_x, :max_y, :bounding_width, :bounding_height, :name
|
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 Rubyshop
|
|
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?
|
@@ -38,11 +39,13 @@ module Rubyshop
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def layer(options, &block)
|
41
|
-
if options.is_a?
|
42
|
+
if options.is_a? RComposite::Layer
|
42
43
|
layer = options
|
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 Rubyshop
|
|
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)
|
@@ -89,9 +91,9 @@ module Rubyshop
|
|
89
91
|
def composite_layers(image, layers)
|
90
92
|
layers.reverse.each do |layer|
|
91
93
|
case layer
|
92
|
-
when
|
94
|
+
when RComposite::LayerSet
|
93
95
|
image = composite_layers image, layer.layers
|
94
|
-
when
|
96
|
+
when RComposite::Layer
|
95
97
|
layer.merge_down image
|
96
98
|
end
|
97
99
|
end
|
@@ -114,7 +116,7 @@ module Rubyshop
|
|
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 Rubyshop
|
|
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
|
metadata
CHANGED
@@ -1,62 +1,73 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.9.0
|
3
|
-
specification_version: 1
|
4
2
|
name: rubyshop
|
5
3
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.
|
7
|
-
date: 2006-11-10 00:00:00 -05:00
|
8
|
-
summary: Powerful layer based image compositing made easy as pie.
|
9
|
-
require_paths:
|
10
|
-
- lib
|
11
|
-
email: corbanbrook@gmail.com
|
12
|
-
homepage: http://schf.uc.org
|
13
|
-
rubyforge_project: rubyshop
|
14
|
-
description:
|
15
|
-
autorequire: rubyshop
|
16
|
-
default_executable:
|
17
|
-
bindir: bin
|
18
|
-
has_rdoc: false
|
19
|
-
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
-
requirements:
|
21
|
-
- - ">"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: 0.0.0
|
24
|
-
version:
|
4
|
+
version: 0.3.1
|
25
5
|
platform: ruby
|
26
|
-
signing_key:
|
27
|
-
cert_chain:
|
28
|
-
post_install_message:
|
29
6
|
authors:
|
30
7
|
- Corban Brook
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
- lib/rubyshop/canvas.rb
|
35
|
-
- lib/rubyshop/filllayer.rb
|
36
|
-
- lib/rubyshop/layer.rb
|
37
|
-
- lib/rubyshop/layermask.rb
|
38
|
-
- lib/rubyshop/layerset.rb
|
39
|
-
- lib/rubyshop/rubyshop.rb
|
40
|
-
- LICENSE
|
41
|
-
test_files: []
|
42
|
-
|
43
|
-
rdoc_options: []
|
44
|
-
|
45
|
-
extra_rdoc_files: []
|
46
|
-
|
47
|
-
executables: []
|
48
|
-
|
49
|
-
extensions: []
|
50
|
-
|
51
|
-
requirements: []
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
52
11
|
|
12
|
+
date: 2009-08-13 00:00:00 -04:00
|
13
|
+
default_executable:
|
53
14
|
dependencies:
|
54
15
|
- !ruby/object:Gem::Dependency
|
55
16
|
name: rmagick
|
17
|
+
type: :runtime
|
56
18
|
version_requirement:
|
57
|
-
version_requirements: !ruby/object:Gem::
|
19
|
+
version_requirements: !ruby/object:Gem::Requirement
|
58
20
|
requirements:
|
59
|
-
- - "
|
21
|
+
- - ">="
|
60
22
|
- !ruby/object:Gem::Version
|
61
|
-
version:
|
23
|
+
version: 2.0.0
|
62
24
|
version:
|
25
|
+
description: RComposite (formally Rubyshop) 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)
|
26
|
+
email: corbanbrook@gmail.com
|
27
|
+
executables: []
|
28
|
+
|
29
|
+
extensions: []
|
30
|
+
|
31
|
+
extra_rdoc_files:
|
32
|
+
- README
|
33
|
+
- MIT-LICENSE
|
34
|
+
files:
|
35
|
+
- README
|
36
|
+
- MIT-LICENSE
|
37
|
+
- lib/rcomposite.rb
|
38
|
+
- lib/rcomposite/layer.rb
|
39
|
+
- lib/rcomposite/layerset.rb
|
40
|
+
- lib/rcomposite/adjustmentlayer.rb
|
41
|
+
- lib/rcomposite/filllayer.rb
|
42
|
+
- lib/rcomposite/canvas.rb
|
43
|
+
- lib/rcomposite/layermask.rb
|
44
|
+
has_rdoc: true
|
45
|
+
homepage: http://github.com/corbanbrook/rcomposite
|
46
|
+
licenses: []
|
47
|
+
|
48
|
+
post_install_message:
|
49
|
+
rdoc_options: []
|
50
|
+
|
51
|
+
require_paths:
|
52
|
+
- lib
|
53
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: "0"
|
58
|
+
version:
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: "0"
|
64
|
+
version:
|
65
|
+
requirements: []
|
66
|
+
|
67
|
+
rubyforge_project:
|
68
|
+
rubygems_version: 1.3.5
|
69
|
+
signing_key:
|
70
|
+
specification_version: 3
|
71
|
+
summary: An RMagick abstration layer for easy image compositing
|
72
|
+
test_files: []
|
73
|
+
|
data/LICENSE
DELETED
@@ -1,20 +0,0 @@
|
|
1
|
-
Copyright (c) 2006, Corban Riley
|
2
|
-
All rights reserved.
|
3
|
-
|
4
|
-
Redistribution and use in source and binary forms, with or without
|
5
|
-
modification, are permitted provided that the following conditions are met:
|
6
|
-
|
7
|
-
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
8
|
-
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
9
|
-
* Neither the name of the Corban Riley nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
10
|
-
|
11
|
-
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
12
|
-
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
13
|
-
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
14
|
-
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
|
15
|
-
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
16
|
-
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
17
|
-
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
18
|
-
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
19
|
-
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
20
|
-
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/lib/rubyshop.rb
DELETED