compositor_node 0.1.0

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/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "rspec", "~> 2.3.0"
10
+ gem "bundler", "~> 1.0.0"
11
+ gem "jeweler", "~> 1.6.1"
12
+ gem "rcov", ">= 0"
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,28 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ diff-lcs (1.1.2)
5
+ git (1.2.5)
6
+ jeweler (1.6.1)
7
+ bundler (~> 1.0.0)
8
+ git (>= 1.2.5)
9
+ rake
10
+ rake (0.9.0)
11
+ rcov (0.9.9)
12
+ rspec (2.3.0)
13
+ rspec-core (~> 2.3.0)
14
+ rspec-expectations (~> 2.3.0)
15
+ rspec-mocks (~> 2.3.0)
16
+ rspec-core (2.3.1)
17
+ rspec-expectations (2.3.0)
18
+ diff-lcs (~> 1.1.2)
19
+ rspec-mocks (2.3.0)
20
+
21
+ PLATFORMS
22
+ ruby
23
+
24
+ DEPENDENCIES
25
+ bundler (~> 1.0.0)
26
+ jeweler (~> 1.6.1)
27
+ rcov
28
+ rspec (~> 2.3.0)
data/LICENSE.txt ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 Andrew Donaldson http://dies-el.co.uk/
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,29 @@
1
+ Compositor Node
2
+ ===============
3
+
4
+ Node based composition:
5
+ http://en.wikipedia.org/wiki/Digital_compositing#Node-based_and_layer-based_compositing
6
+
7
+ The intention of this library is to make it easy to build up a structure of nodes which will then be output to a flat file. Imagine using this library as part of a web-app that makes it easy to manipulate images in a structured, visual way (without say, Photoshop).
8
+
9
+ To run the example, type:
10
+
11
+ >> ruby main.rb
12
+
13
+ This will:
14
+
15
+ - Create an image node from a large image ($oversized_image)
16
+ - Create an image node of some text (transparent PNG) ($overlay_text)
17
+
18
+ - Create a resizer node which resizes its source ($oversized_image) to new dimensions
19
+ - Create a resizer node which resizes its source ($overlay_text) to new dimensions (only width is supplied so it keeps aspect ratio)
20
+
21
+ - Create a blender node which mixes together its sources (the resized $oversized_image, $overlay_text) using a 'multiply' method. Offsets $overlay_text by 50 pixels.
22
+
23
+ - Create a cropper node which crops the source ($blender) to a particular size / offset
24
+
25
+ - Create an output node which will write out it's source (the output of $cropper) at a paticular size, to data/output.png
26
+
27
+ Licensed under MIT (see MIT-LICENSE.txt)
28
+
29
+ Copyright (c) 2010 Andrew Donaldson http://dies-el.co.uk/
data/README.rdoc ADDED
@@ -0,0 +1,19 @@
1
+ = compositor_node
2
+
3
+ Description goes here.
4
+
5
+ == Contributing to compositor_node
6
+
7
+ * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
8
+ * Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
9
+ * Fork the project
10
+ * Start a feature/bugfix branch
11
+ * Commit and push until you are happy with your contribution
12
+ * Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
13
+ * Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2011 Andrew Donaldson. See LICENSE.txt for
18
+ further details.
19
+
data/Rakefile ADDED
@@ -0,0 +1,52 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "compositor_node"
18
+ gem.homepage = "http://github.com/dies-el/compositor_node"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Ruby library that provides a framework for node-based composition of images.}
21
+ gem.description = %Q{Node based composition:
22
+ http://en.wikipedia.org/wiki/Digital_compositing#Node-based_and_layer-based_compositing
23
+
24
+ The intention of this library is to make it easy to build up a structure of nodes which will then be output to a flat file. Imagine using this library as part of a web-app that makes it easy to manipulate images in a structured, visual way (without say, Photoshop).}
25
+ gem.email = "andrew@desto.net"
26
+ gem.authors = ["Andrew Donaldson"]
27
+ # dependencies defined in Gemfile
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ require 'rspec/core'
32
+ require 'rspec/core/rake_task'
33
+ RSpec::Core::RakeTask.new(:spec) do |spec|
34
+ spec.pattern = FileList['spec/**/*_spec.rb']
35
+ end
36
+
37
+ RSpec::Core::RakeTask.new(:rcov) do |spec|
38
+ spec.pattern = 'spec/**/*_spec.rb'
39
+ spec.rcov = true
40
+ end
41
+
42
+ task :default => :spec
43
+
44
+ require 'rake/rdoctask'
45
+ Rake::RDocTask.new do |rdoc|
46
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
47
+
48
+ rdoc.rdoc_dir = 'rdoc'
49
+ rdoc.title = "compositor_node #{version}"
50
+ rdoc.rdoc_files.include('README*')
51
+ rdoc.rdoc_files.include('lib/**/*.rb')
52
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,73 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{compositor_node}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Andrew Donaldson"]
12
+ s.date = %q{2011-05-31}
13
+ s.description = %q{Node based composition:
14
+ http://en.wikipedia.org/wiki/Digital_compositing#Node-based_and_layer-based_compositing
15
+
16
+ The intention of this library is to make it easy to build up a structure of nodes which will then be output to a flat file. Imagine using this library as part of a web-app that makes it easy to manipulate images in a structured, visual way (without say, Photoshop).}
17
+ s.email = %q{andrew@desto.net}
18
+ s.extra_rdoc_files = [
19
+ "LICENSE.txt",
20
+ "README",
21
+ "README.rdoc"
22
+ ]
23
+ s.files = [
24
+ ".document",
25
+ ".rspec",
26
+ "Gemfile",
27
+ "Gemfile.lock",
28
+ "LICENSE.txt",
29
+ "README",
30
+ "README.rdoc",
31
+ "Rakefile",
32
+ "VERSION",
33
+ "compositor_node.gemspec",
34
+ "lib/compositor_node.rb",
35
+ "lib/compositor_node/blender.rb",
36
+ "lib/compositor_node/config.rb",
37
+ "lib/compositor_node/cropper.rb",
38
+ "lib/compositor_node/engine.rb",
39
+ "lib/compositor_node/engines/image_magick.rb",
40
+ "lib/compositor_node/image.rb",
41
+ "lib/compositor_node/output.rb",
42
+ "lib/compositor_node/resizer.rb",
43
+ "spec/compositor_node_spec.rb",
44
+ "spec/spec_helper.rb"
45
+ ]
46
+ s.homepage = %q{http://github.com/dies-el/compositor_node}
47
+ s.licenses = ["MIT"]
48
+ s.require_paths = ["lib"]
49
+ s.rubygems_version = %q{1.5.0}
50
+ s.summary = %q{Ruby library that provides a framework for node-based composition of images.}
51
+
52
+ if s.respond_to? :specification_version then
53
+ s.specification_version = 3
54
+
55
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
56
+ s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
57
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
58
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.1"])
59
+ s.add_development_dependency(%q<rcov>, [">= 0"])
60
+ else
61
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
62
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
63
+ s.add_dependency(%q<jeweler>, ["~> 1.6.1"])
64
+ s.add_dependency(%q<rcov>, [">= 0"])
65
+ end
66
+ else
67
+ s.add_dependency(%q<rspec>, ["~> 2.3.0"])
68
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
69
+ s.add_dependency(%q<jeweler>, ["~> 1.6.1"])
70
+ s.add_dependency(%q<rcov>, [">= 0"])
71
+ end
72
+ end
73
+
@@ -0,0 +1,25 @@
1
+ module CompositorNode
2
+ class Blender
3
+ attr_accessor :source_a, :source_b, :x_offset, :y_offset, :method
4
+
5
+ MULTIPLY = 'MULTIPLY'
6
+ OVERLAY = 'OVERLAY'
7
+
8
+ class NoBlendMethodError < RuntimeError; end
9
+
10
+ def initialize(options = {})
11
+ @source_a = options[:source_a]
12
+ @source_b = options[:source_b]
13
+ @method = options[:method]
14
+ @x_offset = options[:x_offset] || 0
15
+ @y_offset = options[:y_offset] || 0
16
+ end
17
+
18
+ def execute
19
+ image_a = @source_a.execute
20
+ image_b = @source_b.execute
21
+
22
+ Engine.blend(image_a, image_b, @x_offset, @y_offset, @method)
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,15 @@
1
+ module CompositorNode
2
+
3
+ class Config
4
+ @@engine = nil
5
+
6
+ def self.engine
7
+ @@engine
8
+ end
9
+
10
+ def self.engine=(value)
11
+ @@engine = value
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,22 @@
1
+ module CompositorNode
2
+
3
+ class Cropper
4
+ attr_accessor :source, :width, :height, :x_offset, :y_offset
5
+
6
+ class MissingDimensionCropError < RuntimeError; end
7
+
8
+ def initialize(options = {})
9
+ @source = options[:source]
10
+ @width = options[:width]
11
+ @height = options[:height]
12
+ @x_offset = options[:x_offset] || 0
13
+ @y_offset = options[:y_offset] || 0
14
+ end
15
+
16
+ def execute
17
+ raise MissingDimensionCropError unless @width && @height
18
+ Engine.crop(@source.execute, @x_offset, @y_offset, @width, @height)
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,43 @@
1
+ module CompositorNode
2
+
3
+ class Engine
4
+
5
+ class NoEngineError < RuntimeError; end
6
+
7
+ def self.execute
8
+ raise Engine::NoEngineError if Config.engine.nil?
9
+ Config.engine
10
+ end
11
+
12
+ def self.read(source)
13
+ execute.read(source)
14
+ end
15
+
16
+ def self.write(source, path)
17
+ execute.write(source, path)
18
+ end
19
+
20
+ def self.resize(source, width, height)
21
+ execute.resize(source, width, height)
22
+ end
23
+
24
+ def self.width(source)
25
+ execute.width(source)
26
+ end
27
+
28
+ def self.height(source)
29
+ execute.height(source)
30
+ end
31
+
32
+ def self.blend(source_a, source_b, x_offset, y_offset, method)
33
+ raise Blender::NoBlendMethodError if method.nil?
34
+ execute.blend(source_a, source_b, x_offset, y_offset, execute.const_get(method))
35
+ end
36
+
37
+ def self.crop(source, x_offset, y_offset, width, height)
38
+ execute.crop(source, x_offset, y_offset, width, height)
39
+ end
40
+
41
+ end
42
+
43
+ end
@@ -0,0 +1,41 @@
1
+ require 'RMagick'
2
+
3
+ module CompositorNode
4
+ module Engines
5
+
6
+ class ImageMagick
7
+ MULTIPLY = ::Magick::MultiplyCompositeOp
8
+ OVERLAY = ::Magick::OverlayCompositeOp
9
+
10
+ def self.read(source)
11
+ ::Magick::ImageList.new(source)
12
+ end
13
+
14
+ def self.write(source, path)
15
+ source.write(path)
16
+ end
17
+
18
+ def self.resize(source, width, height)
19
+ source.resize(width, height)
20
+ end
21
+
22
+ def self.width(source)
23
+ source.columns
24
+ end
25
+
26
+ def self.height(source)
27
+ source.rows
28
+ end
29
+
30
+ def self.blend(source_a, source_b, x_offset, y_offset, method)
31
+ source_a.composite(source_b, x_offset, y_offset, method)
32
+ end
33
+
34
+ def self.crop(source, x_offset, y_offset, width, height)
35
+ source.crop(x_offset, y_offset, width, height)
36
+ end
37
+
38
+ end
39
+
40
+ end
41
+ end
@@ -0,0 +1,13 @@
1
+ module CompositorNode
2
+ class Image
3
+ attr_accessor :source
4
+
5
+ def initialize(options = {})
6
+ @source = options[:source]
7
+ end
8
+
9
+ def execute
10
+ Engine.read(@source)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,13 @@
1
+ module CompositorNode
2
+ class Output
3
+ attr_accessor :source
4
+
5
+ def initialize(options = {})
6
+ @source = options[:source]
7
+ end
8
+
9
+ def write(path)
10
+ Engine.write(@source.execute, path)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,33 @@
1
+ module CompositorNode
2
+ class Resizer
3
+ attr_accessor :source, :width, :height
4
+
5
+ class MissingDimensionResizeError < RuntimeError; end
6
+
7
+ def initialize(options = {})
8
+ @source = options[:source]
9
+ @width = options[:width]
10
+ @height = options[:height]
11
+ end
12
+
13
+ def execute
14
+ raise MissingDimensionResizeError unless @width || @height
15
+ source = @source.execute
16
+
17
+ unless @width && @height
18
+ original_width = Engine.width(source)
19
+ original_height = Engine.height(source)
20
+
21
+ if @width
22
+ ratio = original_width / @width.to_f
23
+ @height = original_height / ratio
24
+ elsif @height
25
+ ratio = original_height / @height.to_f
26
+ @width = original_width / ratio
27
+ end
28
+ end
29
+
30
+ Engine.resize(source, @width, @height)
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,7 @@
1
+ require 'compositor_node/config.rb'
2
+ require 'compositor_node/engine.rb'
3
+ require 'compositor_node/image.rb'
4
+ require 'compositor_node/blender.rb'
5
+ require 'compositor_node/resizer.rb'
6
+ require 'compositor_node/cropper.rb'
7
+ require 'compositor_node/output.rb'
@@ -0,0 +1,7 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
2
+
3
+ describe "CompositorNode" do
4
+ it "fails" do
5
+ fail "hey buddy, you should probably rename this file and start specing for real"
6
+ end
7
+ end
@@ -0,0 +1,12 @@
1
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
3
+ require 'rspec'
4
+ require 'compositor_node'
5
+
6
+ # Requires supporting files with custom matchers and macros, etc,
7
+ # in ./support/ and its subdirectories.
8
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
9
+
10
+ RSpec.configure do |config|
11
+
12
+ end
metadata ADDED
@@ -0,0 +1,154 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: compositor_node
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Andrew Donaldson
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-05-31 00:00:00 +01:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ type: :development
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 2
31
+ - 3
32
+ - 0
33
+ version: 2.3.0
34
+ name: rspec
35
+ version_requirements: *id001
36
+ prerelease: false
37
+ - !ruby/object:Gem::Dependency
38
+ type: :development
39
+ requirement: &id002 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ~>
43
+ - !ruby/object:Gem::Version
44
+ hash: 23
45
+ segments:
46
+ - 1
47
+ - 0
48
+ - 0
49
+ version: 1.0.0
50
+ name: bundler
51
+ version_requirements: *id002
52
+ prerelease: false
53
+ - !ruby/object:Gem::Dependency
54
+ type: :development
55
+ requirement: &id003 !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ~>
59
+ - !ruby/object:Gem::Version
60
+ hash: 13
61
+ segments:
62
+ - 1
63
+ - 6
64
+ - 1
65
+ version: 1.6.1
66
+ name: jeweler
67
+ version_requirements: *id003
68
+ prerelease: false
69
+ - !ruby/object:Gem::Dependency
70
+ type: :development
71
+ requirement: &id004 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ hash: 3
77
+ segments:
78
+ - 0
79
+ version: "0"
80
+ name: rcov
81
+ version_requirements: *id004
82
+ prerelease: false
83
+ description: |-
84
+ Node based composition:
85
+ http://en.wikipedia.org/wiki/Digital_compositing#Node-based_and_layer-based_compositing
86
+
87
+ The intention of this library is to make it easy to build up a structure of nodes which will then be output to a flat file. Imagine using this library as part of a web-app that makes it easy to manipulate images in a structured, visual way (without say, Photoshop).
88
+ email: andrew@desto.net
89
+ executables: []
90
+
91
+ extensions: []
92
+
93
+ extra_rdoc_files:
94
+ - LICENSE.txt
95
+ - README
96
+ - README.rdoc
97
+ files:
98
+ - .document
99
+ - .rspec
100
+ - Gemfile
101
+ - Gemfile.lock
102
+ - LICENSE.txt
103
+ - README
104
+ - README.rdoc
105
+ - Rakefile
106
+ - VERSION
107
+ - compositor_node.gemspec
108
+ - lib/compositor_node.rb
109
+ - lib/compositor_node/blender.rb
110
+ - lib/compositor_node/config.rb
111
+ - lib/compositor_node/cropper.rb
112
+ - lib/compositor_node/engine.rb
113
+ - lib/compositor_node/engines/image_magick.rb
114
+ - lib/compositor_node/image.rb
115
+ - lib/compositor_node/output.rb
116
+ - lib/compositor_node/resizer.rb
117
+ - spec/compositor_node_spec.rb
118
+ - spec/spec_helper.rb
119
+ has_rdoc: true
120
+ homepage: http://github.com/dies-el/compositor_node
121
+ licenses:
122
+ - MIT
123
+ post_install_message:
124
+ rdoc_options: []
125
+
126
+ require_paths:
127
+ - lib
128
+ required_ruby_version: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ hash: 3
134
+ segments:
135
+ - 0
136
+ version: "0"
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ none: false
139
+ requirements:
140
+ - - ">="
141
+ - !ruby/object:Gem::Version
142
+ hash: 3
143
+ segments:
144
+ - 0
145
+ version: "0"
146
+ requirements: []
147
+
148
+ rubyforge_project:
149
+ rubygems_version: 1.5.0
150
+ signing_key:
151
+ specification_version: 3
152
+ summary: Ruby library that provides a framework for node-based composition of images.
153
+ test_files: []
154
+